Example usage for java.lang Math ulp

List of usage examples for java.lang Math ulp

Introduction

In this page you can find the example usage for java.lang Math ulp.

Prototype

public static float ulp(float f) 

Source Link

Document

Returns the size of an ulp of the argument.

Usage

From source file:uk.ac.diamond.scisoft.analysis.fitting.functions.Polynomial.java

private static Complex[] sort(Complex[] values) {
    // reorder to NumPy's roots output
    List<Complex> rts = Arrays.asList(values);
    Collections.sort(rts, new Comparator<Complex>() {
        @Override/*w w  w.j  a va  2s .  c om*/
        public int compare(Complex o1, Complex o2) {
            double a = o1.getReal();
            double b = o2.getReal();

            double u = 10 * Math.ulp(Math.max(Math.abs(a), Math.abs(b)));
            if (Math.abs(a - b) > u)
                return a < b ? -1 : 1;

            a = o1.getImaginary();
            b = o2.getImaginary();
            if (a == b)
                return 0;
            return a < b ? 1 : -1;
        }
    });

    return rts.toArray(new Complex[0]);
}