Class MathUtils


  • public class MathUtils
    extends Object
    Various math utility methods, also backports from later JDK versions.
    Since:
    1.3.4
    Author:
    Michael Nitschinger
    • Constructor Detail

      • MathUtils

        public MathUtils()
    • Method Detail

      • floorMod

        public static long floorMod​(long x,
                                    long y)
        Backport of floorMod from the JDK since we need to support 1.6. Returns the largest (closest to positive infinity) long value that is less than or equal to the algebraic quotient. There is one special case, if the dividend is the Long.MIN_VALUE and the divisor is -1, then integer overflow occurs and the result is equal to the Long.MIN_VALUE.

        Normal integer division operates under the round to zero rounding mode (truncation). This operation instead acts under the round toward negative infinity (floor) rounding mode. The floor rounding mode gives different results than truncation when the exact result is negative.

        Parameters:
        x - the dividend
        y - the divisor
        Returns:
        the largest (closest to positive infinity) long value that is less than or equal to the algebraic quotient.
        Throws:
        ArithmeticException - if the divisor y is zero
      • floorDiv

        public static long floorDiv​(long x,
                                    long y)
        Backport of floorDiv from the JDK since we need to support 1.6. Returns the largest (closest to positive infinity) long value that is less than or equal to the algebraic quotient. There is one special case, if the dividend is the Long.MIN_VALUE and the divisor is -1, then integer overflow occurs and the result is equal to the Long.MIN_VALUE.

        Normal integer division operates under the round to zero rounding mode (truncation). This operation instead acts under the round toward negative infinity (floor) rounding mode. The floor rounding mode gives different results than truncation when the exact result is negative.

        Parameters:
        x - the dividend
        y - the divisor
        Returns:
        the largest (closest to positive infinity) long value that is less than or equal to the algebraic quotient.
        Throws:
        ArithmeticException - if the divisor y is zero
        See Also:
        floorMod(long, long)