Package org.ddolib.util
Class MathUtil
java.lang.Object
org.ddolib.util.MathUtil
Utility class providing mathematical operations with saturation semantics.
Saturated operations ensure that results do not overflow or underflow,
returning Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY
instead of exceeding the representable range of a double.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublesaturatedAdd(double a, double b) Performs a saturated addition of two double values.static doublesaturatedDiff(double a, double b) Performs a saturated subtraction of two double values.
-
Constructor Details
-
MathUtil
public MathUtil()
-
-
Method Details
-
saturatedAdd
public static double saturatedAdd(double a, double b) Performs a saturated addition of two double values.If the addition overflows the maximum representable double, the result is
Double.POSITIVE_INFINITY. If it underflows below the minimum representable double, the result isDouble.NEGATIVE_INFINITY.- Parameters:
a- the first operandb- the second operand- Returns:
- the saturated sum of
aandb
-
saturatedDiff
public static double saturatedDiff(double a, double b) Performs a saturated subtraction of two double values.If the subtraction overflows the maximum representable double, the result is
Double.POSITIVE_INFINITY. If it underflows below the minimum representable double, the result isDouble.NEGATIVE_INFINITY.- Parameters:
a- the minuendb- the subtrahend- Returns:
- the saturated difference
a - b
-