|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.github.kiprobinson.bigfraction.util.DoubleUtil
public final class DoubleUtil
Additional utilities for working with double values. Useful to prevent hard-coding IEEE 754 constants in code.
Consider this a complement to the methods provided in Double.
| Field Summary | |
|---|---|
static int |
MAX_EXPONENT
The largest permitted exponent value, when using an exponent with offset. |
static int |
MAX_EXPONENT_BITS
The largest permitted exponent value, when using raw exponent bits. |
static long |
MAX_MANTISSA
The largest permitted mantissa value. |
static int |
MIN_EXPONENT
The smallest permitted exponent value, when using an exponent with offset. |
| Method Summary | |
|---|---|
static long[] |
getAllParts(double d)
Returns an array containing the parts of the double. |
static long[] |
getAllParts(double d,
boolean exponentAsBits)
Returns an array containing the parts of the double. |
static double |
getDouble(int sign,
int exponent,
long mantissa)
Creates a new double primitive using the provided component bits. |
static double |
getDouble(int sign,
int exponent,
long mantissa,
boolean exponentAsBits)
Creates a new double primitive using the provided component bits. |
static int |
getExponent(double d)
Returns the exponent, after adding the exponent offset to the exponent bits. |
static int |
getExponentBits(double d)
Returns the raw exponent bits, without adjusting for the offset. |
static long |
getMantissa(double d)
Returns the mantissa bits (bits 51-0). |
static int |
getSign(double d)
Returns the sign bit (bit 63). |
static boolean |
isFinite(double d)
Returns true if d is finite--not infinite and not NaN. |
static boolean |
isSubnormal(double d)
Returns whether or not this double is a subnormal value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long MAX_MANTISSA
public static final int MAX_EXPONENT_BITS
public static final int MIN_EXPONENT
public static final int MAX_EXPONENT
| Method Detail |
|---|
public static boolean isFinite(double d)
d - a double value
public static int getSign(double d)
d - a double value
public static int getExponent(double d)
getExponent(0.5) == -1 because 1.0 == 1.0 * 2^-1getExponent(1.0) == 0 because 1.0 == 1.0 * 2^0getExponent(2.0) == 1 because 2.0 == 1.0 * 2^1
d - any double value
public static int getExponentBits(double d)
getExponentBits(0.5) == 0x3fegetExponentBits(1.0) == 0x3ffgetExponentBits(2.0) == 0x400
d - a double value
public static long getMantissa(double d)
d - a double value
public static boolean isSubnormal(double d)
d - a double value
public static long[] getAllParts(double d)
d - a double value
public static long[] getAllParts(double d,
boolean exponentAsBits)
d - a double valueexponentAsBits - whether to return exponent as raw bits rather than adjusted value
public static double getDouble(int sign,
int exponent,
long mantissa)
sign - sign bitexponent - adjusted exponentmantissa - mantissa bits
IllegalArgumentException - if any of the parts contain invalid bits.
public static double getDouble(int sign,
int exponent,
long mantissa,
boolean exponentAsBits)
sign - sign bitexponent - exponent (either raw bits or adjusted value)mantissa - mantissa bitsexponentAsBits - If true, assumes that exponent parameter represents the actual exponent bits. If false,
IEEE exponent offset value will be added to the offset to get the bits.
IllegalArgumentException - if any of the parts contain invalid bits.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||