Package com.mckoi.util
Class BigNumber
java.lang.Object
java.lang.Number
com.mckoi.util.BigNumber
- All Implemented Interfaces:
Serializable
Extends BigDecimal to allow a number to be positive infinity, negative
infinity and not-a-number. This provides compatibility with float and
double types.
- Author:
- Tobias Downer
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionabs()Returns the big number as a BigDecimal object.byteReturns this big number as a byte.booleanReturns true if this BigNumber can be represented by a 32-bit int (has no scale).booleanReturns true if this BigNumber can be represented by a 64-bit long (has no scale).intCompares this BigNumber with the given BigNumber.doubleReturns this big number as a double.booleanThe equals comparison uses the BigDecimal 'equals' method to compare values.floatReturns this big number as a float.static BigNumberfromBigDecimal(BigDecimal val) Creates a BigNumber from a BigDecimal.static BigNumberfromData(byte[] buf, int scale, byte state) Creates a BigNumber from the given data.static BigNumberfromDouble(double value) Creates a BigNumber from a double.static BigNumberfromFloat(float value) Creates a BigNumber from a float.static BigNumberfromInt(int value) Creates a BigNumber from an int.static BigNumberfromLong(long value) Creates a BigNumber from a long.static BigNumberfromString(String str) Creates a BigNumber from a string.intgetScale()Returns the scale of this number, or -1 if the number has no scale (if it -inf, +inf or NaN).bytegetState()Returns the state of this number.intintValue()Returns this big number as an int.longReturns this big number as a long.setScale(int d, int round_enum) shortReturns this big number as a short.intsignum()sqrt()byte[]Returns this number as a byte array (unscaled).toString()Returns this big number as a string.
-
Field Details
-
NEGATIVE_INFINITY
Statics for negative infinity, positive infinity and NaN. -
POSITIVE_INFINITY
-
NaN
-
BIG_NUMBER_ZERO
Statics for 0 and 1. -
BIG_NUMBER_ONE
-
-
Method Details
-
canBeRepresentedAsLong
public boolean canBeRepresentedAsLong()Returns true if this BigNumber can be represented by a 64-bit long (has no scale). -
canBeRepresentedAsInt
public boolean canBeRepresentedAsInt()Returns true if this BigNumber can be represented by a 32-bit int (has no scale). -
getScale
public int getScale()Returns the scale of this number, or -1 if the number has no scale (if it -inf, +inf or NaN). -
getState
public byte getState()Returns the state of this number. Returns either 1 which indicates negative infinity, 2 which indicates positive infinity, or 3 which indicates NaN. -
toByteArray
public byte[] toByteArray()Returns this number as a byte array (unscaled). -
toString
Returns this big number as a string. -
doubleValue
public double doubleValue()Returns this big number as a double.- Specified by:
doubleValuein classNumber
-
floatValue
public float floatValue()Returns this big number as a float.- Specified by:
floatValuein classNumber
-
longValue
public long longValue()Returns this big number as a long. -
intValue
public int intValue()Returns this big number as an int. -
shortValue
public short shortValue()Returns this big number as a short.- Overrides:
shortValuein classNumber
-
byteValue
public byte byteValue()Returns this big number as a byte. -
asBigDecimal
Returns the big number as a BigDecimal object. Note that this throws an arith error if this number represents NaN, +Inf or -Inf. -
compareTo
Compares this BigNumber with the given BigNumber. Returns 0 if the values are equal, >0 if this is greater than the given value, and < 0 if this is less than the given value. -
equals
The equals comparison uses the BigDecimal 'equals' method to compare values. This means that '0' is NOT equal to '0.0' and '10.0' is NOT equal to '10.00'. Care should be taken when using this method. -
bitWiseOr
-
add
-
subtract
-
multiply
-
divide
-
abs
-
signum
public int signum() -
setScale
-
sqrt
-
fromDouble
Creates a BigNumber from a double. -
fromFloat
Creates a BigNumber from a float. -
fromLong
Creates a BigNumber from a long. -
fromInt
Creates a BigNumber from an int. -
fromString
Creates a BigNumber from a string. -
fromBigDecimal
Creates a BigNumber from a BigDecimal. -
fromData
Creates a BigNumber from the given data.
-