public class ExtraMath extends Object
Modifier and Type | Field and Description |
---|---|
static double |
CLOSE |
static double |
EPSILON |
Constructor and Description |
---|
ExtraMath() |
Modifier and Type | Method and Description |
---|---|
static boolean |
close(double v,
double w) |
static boolean |
close(double v,
double w,
double tol)
Are v and w "close" to each other?
|
static double |
closeFloor(double v)
Returns floor(v) except when v is very close to the next number, when it returns ceil(v);
|
static double |
round(double x,
int n)
Round the argument x to n decimal places.
|
public static boolean close(double v, double w, double tol)
public static boolean close(double v, double w)
public static double closeFloor(double v)
public static double round(double x, int n)
For sufficiently small x*10n, the rounding is to zero, and the return value is a signed zero (same sign as x). Suppose x = a*2b, where the significand we must have a<2. Sufficiently small means such that n log210 < -(b+2).
For sufficiently large x*10n, the adjustment of rounding is too small to affect the least significant bit. That is a*2b represents an amount greater than one, and rounding no longer affects the value, and the return is x. Since the matissa has 52 fractional bits, sufficiently large means such that n log210 > 52-b.
x
- to roundn
- decimal places