Here you can find the source of almost(double a, double b, double prec)
public static boolean almost(double a, double b, double prec)
//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; } }