Class BigIntegerNumber
java.lang.Object
java.lang.Number
org.znerd.math.RealNumber
org.znerd.math.RationalNumber
org.znerd.math.IntegerNumber
org.znerd.math.BigIntegerNumber
- All Implemented Interfaces:
Serializable, Comparable, RoundingModes
Basic implementation of an integer number. This implementation is based on
a
java.math.BigInteger. It can hold all values from
-2**32 to (2**32 - 1).
Instances must be obtained by using the
createInstance() factory method.- Version:
- $Revision: 1.8 $ $Date: 2002/10/01 18:46:31 $
- Author:
- Ernst de Haan (znerd@FreeBSD.org)
- See Also:
-
Field Summary
Fields inherited from class RealNumber
MAXIMUM_RADIXFields inherited from interface RoundingModes
ROUND_CEILING, ROUND_DOWN, ROUND_FLOOR, ROUND_UP -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs aBigIntegerNumberfrom aBigInteger. -
Method Summary
Modifier and TypeMethodDescriptionadd(IntegerNumber n) Computes this + n, where n is an integer number.static BigIntegerNumberReturns an instance of aBigIntegerNumberbased on ajava.math.BigInteger.doubleReturns the value of this number as adouble.inthashCode()Computes the integer result of this/n, where n is an integer number.longReturns the value of this number as along.Computes this * n, where n is an integer number.protected RationalNumberpowImpl(int exponent) Converts the value of this number to aBigInteger.byte[]Returns the two's-complement representation of this integer number.Methods inherited from class IntegerNumber
abs, absInteger, add, compareTo, compareToImpl, compareToImpl, dec, divide, fac, gcd, inc, invert, isRelativePrime, multiply, negate, negateInteger, powImpl, remainder, subtract, subtract, toBigDecimal, toBigDecimal, toBigDecimal, truncMethods inherited from class RationalNumber
add, compareTo, compareToImpl, compareToImpl2, divide, getDenominator, getNumerator, multiply, pow, powImpl, subtractMethods inherited from class RealNumber
byteValue, compareTo, compareTo, equals, fitsByte, fitsDouble, fitsFloat, fitsInt, fitsLong, fitsShort, floatValue, getSign, intValue, pow, round, shortValue, toString
-
Constructor Details
-
BigIntegerNumber
Constructs aBigIntegerNumberfrom aBigInteger.- Parameters:
n- the value for the new number, notnull.- Throws:
IllegalArgumentException- ifn == null.
-
-
Method Details
-
createInstance
Returns an instance of aBigIntegerNumberbased on ajava.math.BigInteger.- Parameters:
n- theBigIntegerto construct aBigIntegerNumberfrom.- Returns:
- the (possibly newly constructed)
BigIntegerNumberinstance. - Throws:
IllegalArgumentException- ifn == null.
-
hashCode
-
add
Description copied from class:IntegerNumberComputes this + n, where n is an integer number.- Specified by:
addin classIntegerNumber- Parameters:
n- the number to add to this, notnull.- Returns:
- the sum of this and n, never
null. - Throws:
IllegalArgumentException- if the argument isnull.
-
multiply
Description copied from class:IntegerNumberComputes this * n, where n is an integer number.- Specified by:
multiplyin classIntegerNumber- Parameters:
n- the number to multiply this by, notnull.- Returns:
- the product of this and n, not
null. - Throws:
IllegalArgumentException- ifn == null.
-
integerDivide
public IntegerNumber integerDivide(IntegerNumber n) throws ArithmeticException, IllegalArgumentException Description copied from class:IntegerNumberComputes the integer result of this/n, where n is an integer number.- Specified by:
integerDividein classIntegerNumber- Parameters:
n- the number to divide this by.- Returns:
- the integer result of this divided by n.
- Throws:
ArithmeticException- if the value of the argument number is zero.IllegalArgumentException- if the argument isnull.
-
powImpl
-
longValue
public long longValue()Description copied from class:RealNumberReturns the value of this number as along. This may involve rounding.- Overrides:
longValuein classRealNumber- Returns:
- the numeric value represented by this object after conversion
to type
long.
-
doubleValue
public double doubleValue()Description copied from class:RealNumberReturns the value of this number as adouble. This may involve rounding.- Overrides:
doubleValuein classRationalNumber- Returns:
- the numeric value represented by this object after conversion
to type
double.
-
toByteArray
public byte[] toByteArray()Description copied from class:IntegerNumberReturns the two's-complement representation of this integer number. The array is big-endian (i.e., the most significant byte is in the [0] position). The array contains the minimum number of bytes required to represent the number.- Specified by:
toByteArrayin classIntegerNumber- Returns:
- a byte array containing the bits of this integer number.
-
toBigInteger
Description copied from class:IntegerNumberConverts the value of this number to aBigInteger.- Overrides:
toBigIntegerin classIntegerNumber- Returns:
- a
BigIntegerwith the value of this.
-