Java Double Number Almost Equal almost(double a, double b, double prec)

Here you can find the source of almost(double a, double b, double prec)

Description

almost

License

Open Source License

Declaration

public static boolean almost(double a, double b, double prec) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static boolean almost(double a, double b, double prec) {
        return Math.abs(a - b) / Math.abs(a + b) <= prec || (almostZero(a) && almostZero(b));
    }// w  ww.  j a v  a 2 s.  c o  m

    public static boolean almost(double a, double b) {
        return Math.abs(a - b) / Math.abs(a + b) <= 1e-10 || (almostZero(a) && almostZero(b));
    }

    public static boolean almostZero(double a) {
        return Math.abs(a) <= 1e-30;
    }
}

Related

  1. almostEqual(double a, double b)
  2. almostEqual(double a, double b, double delta)
  3. almostEqual(double[][] a, double[][] b, double delta)
  4. almostEqual(final double aDouble, final double otherDouble)