Browse Source

PrismUtils#doublesAreClose with filtering via an IterableInt

master
Steffen Märcker 8 years ago
committed by Dave Parker
parent
commit
c25c745ae9
  1. 28
      prism/src/prism/PrismUtils.java

28
prism/src/prism/PrismUtils.java

@ -36,6 +36,8 @@ import java.util.PrimitiveIterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import common.iterable.IterableInt;
/**
* Various general-purpose utility methods in Java
*/
@ -118,22 +120,32 @@ public class PrismUtils
*/
public static boolean doublesAreClose(double d1[], double d2[], double epsilon, boolean abs)
{
int i, n;
n = Math.min(d1.length, d2.length);
int n = Math.min(d1.length, d2.length);
if (abs) {
for (i = 0; i < n; i++) {
if (!PrismUtils.doublesAreCloseAbs(d1[i], d2[i], epsilon))
for (int i = 0; i < n; i++) {
if (!doublesAreCloseAbs(d1[i], d2[i], epsilon))
return false;
}
} else {
for (i = 0; i < n; i++) {
if (!PrismUtils.doublesAreCloseRel(d1[i], d2[i], epsilon))
for (int i = 0; i < n; i++) {
if (!doublesAreCloseRel(d1[i], d2[i], epsilon))
return false;
}
}
return true;
}
/**
* See if, for all the entries given by the {@code indizes}
* iterator, two arrays of doubles are all within epsilon of each other (relative or absolute error).
* <br>
* Considers Inf == Inf and -Inf == -Inf.
*/
public static boolean doublesAreClose(double d1[], double d2[], IterableInt indizes, double epsilon, boolean abs)
{
return doublesAreClose(d1, d2, indizes.iterator(), epsilon, abs);
}
/**
* See if, for all the entries given by the {@code indizes}
* iterator, two arrays of doubles are all within epsilon of each other (relative or absolute error).
@ -145,13 +157,13 @@ public class PrismUtils
if (abs) {
while (indizes.hasNext()) {
int i = indizes.nextInt();
if (!PrismUtils.doublesAreCloseAbs(d1[i], d2[i], epsilon))
if (!doublesAreCloseAbs(d1[i], d2[i], epsilon))
return false;
}
} else {
while (indizes.hasNext()) {
int i = indizes.nextInt();
if (!PrismUtils.doublesAreCloseRel(d1[i], d2[i], epsilon))
if (!doublesAreCloseRel(d1[i], d2[i], epsilon))
return false;
}
}

Loading…
Cancel
Save