Here you can find the source of epsilonEquals(final double a, final double b, final double epsilon)
Parameter | Description |
---|---|
a | first value to compare |
b | second value to compare |
epsilon | amount of difference allowed |
public static boolean epsilonEquals(final double a, final double b, final double epsilon)
//package com.java2s; public class Main { /**//from w w w.j a v a 2s . c om * Calculate whether the two scalars (<tt>a</tt> and <tt>b</tt>) are equal, * given some slack value <tt>epsilon</tt>. This allows floating point * values to be compared for approximate equality, such that floating point * errors are alleviated. * * @param a first value to compare * @param b second value to compare * @param epsilon amount of difference allowed * @return true if the values with epsilon, false otherwise */ public static boolean epsilonEquals(final double a, final double b, final double epsilon) { final double diff = a - b; return diff < epsilon && diff > 0d - epsilon; } }