Example usage for org.apache.commons.math3.util Precision equalsIncludingNaN

List of usage examples for org.apache.commons.math3.util Precision equalsIncludingNaN

Introduction

In this page you can find the example usage for org.apache.commons.math3.util Precision equalsIncludingNaN.

Prototype

public static boolean equalsIncludingNaN(double x, double y, int maxUlps) 

Source Link

Document

Returns true if both arguments are NaN or if they are equal as defined by #equals(double,double,int) equals(x, y, maxUlps) .

Usage

From source file:lirmm.inria.fr.math.TestUtils.java

/** verifies that two arrays are close (sup norm) */
public static void assertEquals(String msg, double[] expected, double[] observed, double tolerance) {
    StringBuilder out = new StringBuilder(msg);
    if (expected.length != observed.length) {
        out.append("\n Arrays not same length. \n");
        out.append("expected has length ");
        out.append(expected.length);//  www. ja va2 s  .  c o m
        out.append(" observed length = ");
        out.append(observed.length);
        Assert.fail(out.toString());
    }
    boolean failure = false;
    for (int i = 0; i < expected.length; i++) {
        if (!Precision.equalsIncludingNaN(expected[i], observed[i], tolerance)) {
            failure = true;
            out.append("\n Elements at index ");
            out.append(i);
            out.append(" differ. ");
            out.append(" expected = ");
            out.append(expected[i]);
            out.append(" observed = ");
            out.append(observed[i]);
        }
    }
    if (failure) {
        Assert.fail(out.toString());
    }
}