Class MathUtil

java.lang.Object
org.ddolib.util.MathUtil

public class MathUtil extends Object
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 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 is Double.NEGATIVE_INFINITY.

      Parameters:
      a - the first operand
      b - the second operand
      Returns:
      the saturated sum of a and b
    • 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 is Double.NEGATIVE_INFINITY.

      Parameters:
      a - the minuend
      b - the subtrahend
      Returns:
      the saturated difference a - b