| java.lang.Object org.codehaus.groovy.runtime.typehandling.NumberMath
All known Subclasses: org.codehaus.groovy.runtime.typehandling.BigIntegerMath, org.codehaus.groovy.runtime.typehandling.FloatingPointMath, org.codehaus.groovy.runtime.typehandling.BigDecimalMath, org.codehaus.groovy.runtime.typehandling.LongMath, org.codehaus.groovy.runtime.typehandling.IntegerMath,
NumberMath | abstract public class NumberMath extends Object (Code) | | Stateless objects used to perform math on the various Number subclasses.
Instances are required so that polymorphic calls work properly, but each
subclass creates a singleton instance to minimize garbage. All methods
must be thread-safe.
The design goals of this class are as follows:
- Support a 'least surprising' math model to scripting language users. This
means that exact, or decimal math should be used for default calculations. This
scheme assumes that by default, groovy literals with decimal points are instantiated
as BigDecimal objects rather than binary floating points (Float, Double).
- Do not force the appearance of exactness on a number that is by definition not
guaranteed to be exact. In particular this means that if an operand in a NumberMath
operation is a binary floating point number, ensure that the result remains a binary floating point
number (i.e. never automatically promote a binary floating point number to a BigDecimal).
This has the effect of preserving the expectations of binary floating point users and helps performance.
- Provide an implementation that is as close as practical to the Java 1.5 BigDecimal math model
which implements precision based floating point decimal math (ANSI X3.274-1996 and
ANSI X3.274-1996/AM 1-2000 (section 7.4).
author: Steve Goetze |
Method Summary | |
public static Number | abs(Number number) | abstract protected Number | absImpl(Number number) | public static Number | add(Number left, Number right) | abstract protected Number | addImpl(Number left, Number right) | public static Number | and(Number left, Number right) | protected Number | andImpl(Number left, Number right) | public static int | compareTo(Number left, Number right) | abstract protected int | compareToImpl(Number left, Number right) | protected UnsupportedOperationException | createUnsupportedException(String operation, Number left) | public static Number | divide(Number left, Number right) | abstract protected Number | divideImpl(Number left, Number right) | public static Number | intdiv(Number left, Number right) | protected Number | intdivImpl(Number left, Number right) | public static boolean | isBigDecimal(Number number) | public static boolean | isBigInteger(Number number) | public static boolean | isFloatingPoint(Number number) | public static boolean | isInteger(Number number) | public static boolean | isLong(Number number) | public static Number | leftShift(Number left, Number right) For this operation, consider the operands independently. | protected Number | leftShiftImpl(Number left, Number right) | public static Number | mod(Number left, Number right) | protected Number | modImpl(Number left, Number right) | public static Number | multiply(Number left, Number right) | abstract protected Number | multiplyImpl(Number left, Number right) | public static Number | negate(Number left) | abstract protected Number | negateImpl(Number left) | public static Number | or(Number left, Number right) | protected Number | orImpl(Number left, Number right) | public static Number | rightShift(Number left, Number right) For this operation, consider the operands independently. | protected Number | rightShiftImpl(Number left, Number right) | public static Number | rightShiftUnsigned(Number left, Number right) For this operation, consider the operands independently. | protected Number | rightShiftUnsignedImpl(Number left, Number right) | public static Number | subtract(Number left, Number right) | abstract protected Number | subtractImpl(Number left, Number right) | public static BigDecimal | toBigDecimal(Number n) | public static BigInteger | toBigInteger(Number n) | public static Number | xor(Number left, Number right) | protected Number | xorImpl(Number left, Number right) |
isBigDecimal | public static boolean isBigDecimal(Number number)(Code) | | |
isBigInteger | public static boolean isBigInteger(Number number)(Code) | | |
isFloatingPoint | public static boolean isFloatingPoint(Number number)(Code) | | |
isInteger | public static boolean isInteger(Number number)(Code) | | |
leftShift | public static Number leftShift(Number left, Number right)(Code) | | For this operation, consider the operands independently. Throw an exception if the right operand
(shift distance) is not an integral type. For the left operand (shift value) also require an integral
type, but do NOT promote from Integer to Long. This is consistent with Java, and makes sense for the
shift operators.
|
rightShift | public static Number rightShift(Number left, Number right)(Code) | | For this operation, consider the operands independently. Throw an exception if the right operand
(shift distance) is not an integral type. For the left operand (shift value) also require an integral
type, but do NOT promote from Integer to Long. This is consistent with Java, and makes sense for the
shift operators.
|
rightShiftUnsigned | public static Number rightShiftUnsigned(Number left, Number right)(Code) | | For this operation, consider the operands independently. Throw an exception if the right operand
(shift distance) is not an integral type. For the left operand (shift value) also require an integral
type, but do NOT promote from Integer to Long. This is consistent with Java, and makes sense for the
shift operators.
|
|
|