Class IntegerMath
Singleton instance providing NumberMath implementations for int-based operations. Supports all standard operations: addition, subtraction, multiplication, integer division, comparison, and bitwise operations.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionComputes the absolute value of a number.Adds two numbers.Bitwise AND of two numbers.bitwiseNegateImpl(Number left) Bitwise negation of a number.intcompareToImpl(Number left, Number right) Compares two numbers.divideImpl(Number left, Number right) Divides two numbers.intdivImpl(Number left, Number right) Integer division of two numbers.leftShiftImpl(Number left, Number right) Left shift of a number.Modulo of two numbers.multiplyImpl(Number left, Number right) Multiplies two numbers.Bitwise OR of two numbers.remainderImpl(Number left, Number right) Remainder of two numbers.rightShiftImpl(Number left, Number right) Right shift of a number.rightShiftUnsignedImpl(Number left, Number right) Unsigned right shift of a number.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).Bitwise XOR of two numbers.Methods inherited from class org.codehaus.groovy.runtime.typehandling.NumberMath
abs, add, and, bitwiseNegate, compareTo, createUnsupportedException, divide, getMath, intdiv, isBigDecimal, isBigInteger, isByte, isFloatingPoint, isInteger, isLong, isShort, leftShift, mod, multiply, or, remainder, rightShift, rightShiftUnsigned, subtract, toBigDecimal, toBigInteger, unaryMinus, unaryPlus, xor
-
Field Details
-
INSTANCE
Singleton instance of IntegerMath.
-
-
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
-
orImpl
Description copied from class:NumberMathBitwise OR of two numbers.Default implementation throws UnsupportedOperationException. Subclasses supporting bitwise operations must override.
- Overrides:
orImplin classNumberMath- Parameters:
left- the first operandright- the second operand- Returns:
- the bitwise OR result
-
andImpl
Description copied from class:NumberMathBitwise AND of two numbers.Default implementation throws UnsupportedOperationException. Subclasses supporting bitwise operations must override.
- Overrides:
andImplin classNumberMath- Parameters:
left- the first operandright- the second operand- Returns:
- the bitwise AND result
-
xorImpl
Description copied from class:NumberMathBitwise XOR of two numbers.Default implementation throws UnsupportedOperationException. Subclasses supporting bitwise operations must override.
- Overrides:
xorImplin classNumberMath- Parameters:
left- the first operandright- the second operand- Returns:
- the bitwise XOR result
-
intdivImpl
Description copied from class:NumberMathInteger division of two numbers.Default implementation throws UnsupportedOperationException. Subclasses supporting integer division must override.
- Overrides:
intdivImplin classNumberMath- Parameters:
left- the dividendright- the divisor- Returns:
- the integer quotient
-
modImpl
Description copied from class:NumberMathModulo of two numbers.Default implementation throws UnsupportedOperationException. Subclasses supporting modulo must override.
- Overrides:
modImplin classNumberMath- Parameters:
left- the dividendright- the divisor- Returns:
- the modulo result
-
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
-
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
-
bitwiseNegateImpl
Description copied from class:NumberMathBitwise negation of a number.Default implementation throws UnsupportedOperationException. Subclasses supporting bitwise operations must override.
- Overrides:
bitwiseNegateImplin classNumberMath- Parameters:
left- the operand- Returns:
- the bitwise negation
-
leftShiftImpl
Description copied from class:NumberMathLeft shift of a number.Default implementation throws UnsupportedOperationException. Subclasses supporting bit shifting must override.
- Overrides:
leftShiftImplin classNumberMath- Parameters:
left- the value to shiftright- the shift distance- Returns:
- the left-shifted value
-
rightShiftImpl
Description copied from class:NumberMathRight shift of a number.Default implementation throws UnsupportedOperationException. Subclasses supporting bit shifting must override.
- Overrides:
rightShiftImplin classNumberMath- Parameters:
left- the value to shiftright- the shift distance- Returns:
- the right-shifted value
-
rightShiftUnsignedImpl
Description copied from class:NumberMathUnsigned right shift of a number.Default implementation throws UnsupportedOperationException. Subclasses supporting bit shifting must override.
- Overrides:
rightShiftUnsignedImplin classNumberMath- Parameters:
left- the value to shiftright- the shift distance- Returns:
- the unsigned right-shifted value
-