fr.cnes.sirius.patrius.utils
Class Comparators

java.lang.Object
  extended by fr.cnes.sirius.patrius.utils.Comparators

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.

Since:
1.0
Version:
$Id: Comparators.java 17584 2017-05-10 13:26:39Z bignon $
Author:
Thomas TRAPIER
Use sample :

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)

Concurrency :
unconditionally thread-safe

Field Summary
static double DOUBLE_COMPARISON_EPSILON
          The epsilon used for doubles relative comparison
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOUBLE_COMPARISON_EPSILON

public static final double DOUBLE_COMPARISON_EPSILON
The epsilon used for doubles relative comparison

See Also:
Constant Field Values
Method Detail

equals

public static boolean equals(double x,
                             double y)
Tests the equality between doubles with a relative comparison using a default epsilon.

Parameters:
x - first double to be compared
y - second double to be compared
Returns:
a boolean : "true" if the doubles are found equals.

The value "Nan" as input always imply the return "false"

Since:
1.0

equals

public static boolean equals(double x,
                             double y,
                             double eps)
Tests the equality between doubles with a relative comparison using an input epsilon.

Parameters:
x - first double to be compared
y - second double to be compared
eps - epsilon used in the relative comparison
Returns:
a boolean : "true" if the doubles are found equals.

The value "Nan" as input always imply the return "false"

Since:
1.0

lowerOrEqual

public 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.

Parameters:
x - first double to be compared
y - second double to be compared
Returns:
a boolean : "true" if x is found lower or equal to y.

The value "Nan" as input always imply the return "false"

Since:
1.0

lowerOrEqual

public 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.

Parameters:
x - first double to be compared
y - second double to be compared
eps - epsilon used in the relative comparison
Returns:
a boolean : "true" if x is found lower or equal to y.

The value "Nan" as input always imply the return "false"

Since:
1.0

greaterOrEqual

public 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.

Parameters:
x - first double to be compared
y - second double to be compared
Returns:
a boolean : "true" if x is found greater or equal to y.

The value "Nan" as input always imply the return "false"

Since:
1.0

greaterOrEqual

public 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.

Parameters:
x - first double to be compared
y - second double to be compared
eps - epsilon used in the relative comparison
Returns:
a boolean : "true" if x is found greater or equal to y.

The value "Nan" as input always imply the return "false"

Since:
1.0

lowerStrict

public static boolean lowerStrict(double x,
                                  double y)
Tests if a double is strictly lower than another with a relative comparison using a default epsilon.

Parameters:
x - first double to be compared
y - second double to be compared
Returns:
a boolean : "true" if x is found lower than y.

The value "Nan" as input always imply the return "false"

Since:
1.0

lowerStrict

public 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.

Parameters:
x - first double to be compared
y - second double to be compared
eps - epsilon used in the relative comparison
Returns:
a boolean : "true" if x is found lower than y.

The value "Nan" as input always imply the return "false"

Since:
1.0

equalsWithRelativeTolerance

public static boolean equalsWithRelativeTolerance(double x,
                                                  double y,
                                                  double eps)
Copied from commons math 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.

Parameters:
x - First value.
y - Second value.
eps - Amount of allowed relative error.
Returns:
true if the values are two adjacent floating point numbers or they are within range of each other.
Since:
2.1

greaterStrict

public static boolean greaterStrict(double x,
                                    double y)
Tests if a double is strictly greater than another with a relative comparison using a default epsilon.

Parameters:
x - first double to be compared
y - second double to be compared
Returns:
a boolean : "true" if x is found greater than y.

The value "Nan" as input always imply the return "false"

Since:
1.0

greaterStrict

public 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.

Parameters:
x - first double to be compared
y - second double to be compared
eps - epsilon used in the relative comparison
Returns:
a boolean : "true" if x is found greater than y.

The value "Nan" as input always imply the return "false"

Since:
1.0


Copyright © 2017 CNES. All Rights Reserved.