Class BigDecimalMath

java.lang.Object
org.codehaus.groovy.runtime.typehandling.NumberMath
org.codehaus.groovy.runtime.typehandling.BigDecimalMath

public final class BigDecimalMath extends NumberMath
Arbitrary-precision decimal arithmetic operations.

Singleton instance providing NumberMath implementations for BigDecimal-based operations. Supports exact decimal arithmetic with configurable precision and rounding. This is the default math provider for non-floating-point division operations.

  • Field Details

    • DIVISION_EXTRA_PRECISION

      public static final int DIVISION_EXTRA_PRECISION
      Extra precision added during division when a non-terminating result would otherwise occur.

      Configurable via system property "groovy.division.extra.precision", defaults to 10.

    • DIVISION_MIN_SCALE

      public static final int DIVISION_MIN_SCALE
      Minimum scale (decimal places) for division results.

      Configurable via system property "groovy.division.min.scale", defaults to 10.

    • INSTANCE

      public static final BigDecimalMath INSTANCE
      Singleton instance of BigDecimalMath.
  • Method Details

    • absImpl

      public Number absImpl(Number number)
      Description copied from class: NumberMath
      Computes the absolute value of a number.

      Subclasses must implement this method according to type promotion hierarchy rules.

      Specified by:
      absImpl in class NumberMath
      Parameters:
      number - the operand
      Returns:
      the absolute value
    • addImpl

      public Number addImpl(Number left, Number right)
      Description copied from class: NumberMath
      Adds two numbers.

      Subclasses must implement this method according to type promotion hierarchy rules.

      Specified by:
      addImpl in class NumberMath
      Parameters:
      left - the left operand
      right - the right operand
      Returns:
      the sum
    • subtractImpl

      public Number subtractImpl(Number left, Number right)
      Description copied from class: NumberMath
      Subtracts two numbers.

      Subclasses must implement this method according to type promotion hierarchy rules.

      Specified by:
      subtractImpl in class NumberMath
      Parameters:
      left - the minuend
      right - the subtrahend
      Returns:
      the difference
    • multiplyImpl

      public Number multiplyImpl(Number left, Number right)
      Description copied from class: NumberMath
      Multiplies two numbers.

      Subclasses must implement this method according to type promotion hierarchy rules.

      Specified by:
      multiplyImpl in class NumberMath
      Parameters:
      left - the first multiplicand
      right - the second multiplicand
      Returns:
      the product
    • divideImpl

      public Number divideImpl(Number left, Number right)
      Description copied from class: NumberMath
      Divides two numbers.

      Subclasses must implement this method according to type promotion hierarchy rules.

      Specified by:
      divideImpl in class NumberMath
      Parameters:
      left - the dividend
      right - the divisor
      Returns:
      the quotient
    • compareToImpl

      public int compareToImpl(Number left, Number right)
      Description copied from class: NumberMath
      Compares two numbers.

      Subclasses must implement this method according to type promotion hierarchy rules.

      Specified by:
      compareToImpl in class NumberMath
      Parameters:
      left - the first number
      right - the second number
      Returns:
      negative, zero, or positive as left is less than, equal to, or greater than right
    • unaryMinusImpl

      public Number unaryMinusImpl(Number left)
      Description copied from class: NumberMath
      Negates a number.

      Subclasses must implement this method according to type promotion hierarchy rules.

      Specified by:
      unaryMinusImpl in class NumberMath
      Parameters:
      left - the operand
      Returns:
      the negation
    • unaryPlusImpl

      public Number unaryPlusImpl(Number left)
      Description copied from class: NumberMath
      Returns the number as-is (unary plus/identity).

      Subclasses must implement this method according to type promotion hierarchy rules.

      Specified by:
      unaryPlusImpl in class NumberMath
      Parameters:
      left - the operand
      Returns:
      the same value
    • remainderImpl

      public Number remainderImpl(Number left, Number right)
      Description copied from class: NumberMath
      Remainder of two numbers.

      Default implementation throws UnsupportedOperationException. Subclasses supporting remainder must override.

      Overrides:
      remainderImpl in class NumberMath
      Parameters:
      left - the dividend
      right - the divisor
      Returns:
      the remainder
    • modImpl

      public Number modImpl(Number self, Number divisor)
      Description copied from class: NumberMath
      Modulo of two numbers.

      Default implementation throws UnsupportedOperationException. Subclasses supporting modulo must override.

      Overrides:
      modImpl in class NumberMath
      Parameters:
      self - the dividend
      divisor - the divisor
      Returns:
      the modulo result