public final class Comparators extends Object
- Static comparison methods for real numbers
- Classical methods to compare doubles using an epsilon, as an input or with a default value
See DV-MATHS_30.Those methods can be used this way : if (greaterOrEqual(x, y)) {...}
The condition is "true" if x is greater or equal to y (with a relative comparison using the default epsilon)
Modifier and Type | Field and Description |
---|---|
static double |
DOUBLE_COMPARISON_EPSILON
The epsilon used for doubles relative comparison
|
Modifier and Type | Method and Description |
---|---|
static boolean |
equals(double x,
double y)
Tests the equality between doubles with a relative comparison using a default epsilon.
|
static boolean |
equals(double x,
double y,
double eps)
Tests the equality between doubles with a relative comparison using an input epsilon.
|
static boolean |
equalsWithRelativeTolerance(double x,
double y,
double eps)
Copied from commons math
Precision.equalsWithRelativeTolerance(double, double, double) . |
static boolean |
greaterOrEqual(double x,
double y)
Tests if a double is greater or equal to another with a relative comparison using a default epsilon.
|
static boolean |
greaterOrEqual(double x,
double y,
double eps)
Tests if a double is greater or equal to another with a relative comparison using an input epsilon.
|
static boolean |
greaterStrict(double x,
double y)
Tests if a double is strictly greater than another with a relative comparison using a default epsilon.
|
static boolean |
greaterStrict(double x,
double y,
double eps)
Tests if a double is strictly greater than another with a relative comparison using an input epsilon.
|
static boolean |
lowerOrEqual(double x,
double y)
Tests if a double is lower or equal to another with a relative comparison using a default epsilon.
|
static boolean |
lowerOrEqual(double x,
double y,
double eps)
Tests if a double is lower or equal to another with a relative comparison using an input epsilon.
|
static boolean |
lowerStrict(double x,
double y)
Tests if a double is strictly lower than another with a relative comparison using a default epsilon.
|
static boolean |
lowerStrict(double x,
double y,
double eps)
Tests if a double is strictly lower than another with a relative comparison using an input epsilon.
|
public static final double DOUBLE_COMPARISON_EPSILON
public static boolean equals(double x, double y)
x
- first double to be comparedy
- second double to be comparedThe value "Nan" as input always imply the return "false"
public static boolean equals(double x, double y, double eps)
x
- first double to be comparedy
- second double to be comparedeps
- epsilon used in the relative comparisonThe value "Nan" as input always imply the return "false"
public static boolean lowerOrEqual(double x, double y)
x
- first double to be comparedy
- second double to be comparedThe value "Nan" as input always imply the return "false"
public static boolean lowerOrEqual(double x, double y, double eps)
x
- first double to be comparedy
- second double to be comparedeps
- epsilon used in the relative comparisonThe value "Nan" as input always imply the return "false"
public static boolean greaterOrEqual(double x, double y)
x
- first double to be comparedy
- second double to be comparedThe value "Nan" as input always imply the return "false"
public static boolean greaterOrEqual(double x, double y, double eps)
x
- first double to be comparedy
- second double to be comparedeps
- epsilon used in the relative comparisonThe value "Nan" as input always imply the return "false"
public static boolean lowerStrict(double x, double y)
x
- first double to be comparedy
- second double to be comparedThe value "Nan" as input always imply the return "false"
public static boolean lowerStrict(double x, double y, double eps)
x
- first double to be comparedy
- second double to be comparedeps
- epsilon used in the relative comparisonThe value "Nan" as input always imply the return "false"
public static boolean equalsWithRelativeTolerance(double x, double y, double eps)
Precision.equalsWithRelativeTolerance(double, double, double)
.
Returns true
if the difference between the number is smaller or equal
to the given tolerance.
The difference is the call to the Precision.equals(double, double, int)
. The ulp is 0 instead of 1. This
means that two adjacent numbers are not considered equal.x
- First value.y
- Second value.eps
- Amount of allowed relative error.true
if the values are two adjacent floating point
numbers or they are within range of each other.public static boolean greaterStrict(double x, double y)
x
- first double to be comparedy
- second double to be comparedThe value "Nan" as input always imply the return "false"
public static boolean greaterStrict(double x, double y, double eps)
x
- first double to be comparedy
- second double to be comparedeps
- epsilon used in the relative comparisonThe value "Nan" as input always imply the return "false"
Copyright © 2023 CNES. All rights reserved.