public final class NumberParts extends Object

The representation of a number that can accommodate the range of doubles and longs without loss of precision.

Public Method Summary

double
asDouble()
Returns the double representation of this NumberParts,
long
asLong()
Returns the long representation of this NumberParts,
static NumberParts
create(boolean negative, int exponent, long significand)
boolean
int
exponent()
The actual value of the binary exponent in the floating point encoding.
static NumberParts
fromDouble(double value)
Returns the NumberParts representation of the given double.
static NumberParts
fromLong(long value)
Returns the NumberParts representation of the given long.
int
boolean
isInfinite()
Returns whether this NumberParts represent an infinity (positive or negative).
boolean
isNaN()
Returns whether this NumberParts represents NaN.
boolean
isZero()
Returns whether this NumberParts represents 0.
NumberParts
negate()
Returns this NumberParts with the sign flipped.
boolean
negative()
True if the number was overall negative (i.e.
boolean
representableAsDouble()
Returns whether or not this NumberParts can be represented as a double without loss of precision.
boolean
representableAsLong()
Returns whether or not this NumberParts can be represented as a long without loss of precision.
long
significand()
The value of the significand in the floating point encoding, left justified, with a hidden leading one bit.

Inherited Method Summary

Public Methods

public double asDouble ()

Returns the double representation of this NumberParts,

Throws
IllegalArgumentException if this would lead to a loss of precision.

public long asLong ()

Returns the long representation of this NumberParts,

Throws
IllegalArgumentException if this is not representable as a long.

public static NumberParts create (boolean negative, int exponent, long significand)

Parameters
negative
exponent
significand

public boolean equals (Object o)

Parameters
o

public int exponent ()

The actual value of the binary exponent in the floating point encoding.

public static NumberParts fromDouble (double value)

Returns the NumberParts representation of the given double.

Parameters
value

public static NumberParts fromLong (long value)

Returns the NumberParts representation of the given long.

Parameters
value

public int hashCode ()

public boolean isInfinite ()

Returns whether this NumberParts represent an infinity (positive or negative).

public boolean isNaN ()

Returns whether this NumberParts represents NaN.

There is only one NaN representation in NumberParts (unlike double).

public boolean isZero ()

Returns whether this NumberParts represents 0.

There is only one zero representation in NumberParts (unlike double, which has both negative and positive zero).

public NumberParts negate ()

Returns this NumberParts with the sign flipped.

Returns the same instance for zero (negative 0 is not representable in NumberParts) and NaN.

public boolean negative ()

True if the number was overall negative (i.e. less than zero).

public boolean representableAsDouble ()

Returns whether or not this NumberParts can be represented as a double without loss of precision.

public boolean representableAsLong ()

Returns whether or not this NumberParts can be represented as a long without loss of precision.

public long significand ()

The value of the significand in the floating point encoding, left justified, with a hidden leading one bit.