public class Doubles extends Object
Modifier and Type | Field and Description |
---|---|
static double |
EPSILON
Used as maximal epsilon (difference) when comparing numbers.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
areEqual(double a,
double b)
Determines if the given numbers are equal.
|
static double |
frac(double val)
Returns the fractional part of the given value.
|
static boolean |
isZero(double val)
Determines if the given number is zero (or very very close to).
|
public static final double EPSILON
public static double frac(double val)
The fractional part is "everything behind the decimal separator". So for 1.454 it will be 0.454. This method always returns an absolute value so the fractional part of -4.5656 will be 0.5656.
val
- the number for return the fractional part ofpublic static boolean areEqual(double a, double b)
The numbers are not compared for absolute exactness (as == would do) but a minimal delta (EPSILON
)
is permitted to make up for rounding errors which are in the nature of floating point numbers.
a
- the first number to compareb
- the second number to compareEPSILON
,
false otherwisepublic static boolean isZero(double val)
Determines if the given number is zero or less than EPSILON
away from it. This is used to make up for
rounding errors which are in the nature of floating point numbers.
val
- the number to check if it is 0.EPSILON
,
false otherwiseCopyright © 2018. All rights reserved.