Class BigDecimalMath
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intExtra precision added during division when a non-terminating result would otherwise occur.static final intMinimum scale (decimal places) for division results.static final BigDecimalMathSingleton instance of BigDecimalMath. -
Method Summary
Modifier and TypeMethodDescriptionComputes the absolute value of a number.Adds two numbers.intcompareToImpl(Number left, Number right) Compares two numbers.divideImpl(Number left, Number right) Divides two numbers.Modulo of two numbers.multiplyImpl(Number left, Number right) Multiplies two numbers.remainderImpl(Number left, Number right) Remainder of two numbers.subtractImpl(Number left, Number right) Subtracts two numbers.unaryMinusImpl(Number left) Negates a number.unaryPlusImpl(Number left) Returns the number as-is (unary plus/identity).Methods inherited from class org.codehaus.groovy.runtime.typehandling.NumberMath
abs, add, and, andImpl, bitwiseNegate, bitwiseNegateImpl, compareTo, createUnsupportedException, divide, getMath, intdiv, intdivImpl, isBigDecimal, isBigInteger, isByte, isFloatingPoint, isInteger, isLong, isShort, leftShift, leftShiftImpl, mod, multiply, or, orImpl, remainder, rightShift, rightShiftImpl, rightShiftUnsigned, rightShiftUnsignedImpl, subtract, toBigDecimal, toBigInteger, unaryMinus, unaryPlus, xor, xorImpl
-
Field Details
-
DIVISION_EXTRA_PRECISION
public static final int DIVISION_EXTRA_PRECISIONExtra 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_SCALEMinimum scale (decimal places) for division results.Configurable via system property "groovy.division.min.scale", defaults to 10.
-
INSTANCE
Singleton instance of BigDecimalMath.
-
-
Method Details
-
absImpl
Description copied from class:NumberMathComputes the absolute value of a number.Subclasses must implement this method according to type promotion hierarchy rules.
- Specified by:
absImplin classNumberMath- Parameters:
number- the operand- Returns:
- the absolute value
-
addImpl
Description copied from class:NumberMathAdds two numbers.Subclasses must implement this method according to type promotion hierarchy rules.
- Specified by:
addImplin classNumberMath- Parameters:
left- the left operandright- the right operand- Returns:
- the sum
-
subtractImpl
Description copied from class:NumberMathSubtracts two numbers.Subclasses must implement this method according to type promotion hierarchy rules.
- Specified by:
subtractImplin classNumberMath- Parameters:
left- the minuendright- the subtrahend- Returns:
- the difference
-
multiplyImpl
Description copied from class:NumberMathMultiplies two numbers.Subclasses must implement this method according to type promotion hierarchy rules.
- Specified by:
multiplyImplin classNumberMath- Parameters:
left- the first multiplicandright- the second multiplicand- Returns:
- the product
-
divideImpl
Description copied from class:NumberMathDivides two numbers.Subclasses must implement this method according to type promotion hierarchy rules.
- Specified by:
divideImplin classNumberMath- Parameters:
left- the dividendright- the divisor- Returns:
- the quotient
-
compareToImpl
Description copied from class:NumberMathCompares two numbers.Subclasses must implement this method according to type promotion hierarchy rules.
- Specified by:
compareToImplin classNumberMath- Parameters:
left- the first numberright- the second number- Returns:
- negative, zero, or positive as left is less than, equal to, or greater than right
-
unaryMinusImpl
Description copied from class:NumberMathNegates a number.Subclasses must implement this method according to type promotion hierarchy rules.
- Specified by:
unaryMinusImplin classNumberMath- Parameters:
left- the operand- Returns:
- the negation
-
unaryPlusImpl
Description copied from class:NumberMathReturns the number as-is (unary plus/identity).Subclasses must implement this method according to type promotion hierarchy rules.
- Specified by:
unaryPlusImplin classNumberMath- Parameters:
left- the operand- Returns:
- the same value
-
remainderImpl
Description copied from class:NumberMathRemainder of two numbers.Default implementation throws UnsupportedOperationException. Subclasses supporting remainder must override.
- Overrides:
remainderImplin classNumberMath- Parameters:
left- the dividendright- the divisor- Returns:
- the remainder
-
modImpl
Description copied from class:NumberMathModulo of two numbers.Default implementation throws UnsupportedOperationException. Subclasses supporting modulo must override.
- Overrides:
modImplin classNumberMath- Parameters:
self- the dividenddivisor- the divisor- Returns:
- the modulo result
-