JavaDoubleParser.
References:
| Modifier and Type | Field and Description |
|---|---|
| public static final int | DOUBLE_EXPONENT_BIAS
Bias used in the exponent of a double. |
| pack-priv static final int | DOUBLE_MAX_EXPONENT_POWER_OF_TEN
Largest power of 10 value of the exponent. |
| private static final int | |
| pack-priv static final int | DOUBLE_MIN_EXPONENT_POWER_OF_TEN
Smallest power of 10 value of the exponent. |
| private static final int | |
| private static final double[] | DOUBLE_POWERS_OF_TEN
Precomputed powers of ten from 10^0 to 10^22. |
| public static final int | DOUBLE_SIGNIFICAND_WIDTH
The number of bits in the significand, including the implicit bit. |
| pack-priv static final long[] | MANTISSA_128
A complement to mantissa_64 complete to a 128-bit mantissa. |
| pack-priv static final long[] | MANTISSA_64
When mapping numbers from decimal to binary, we go from w * 10^q to m * 2^p, but we have 10^q = 5^q * 2^q, so effectively we are trying to match w * 2^q * 5^q to m * 2^p. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static double | Returns: the double value, orDouble#NaN if the fast path failed.true if the sign is negative isNegative, long the significand significand, int the exponent number (the power) exponent, boolean true if significand has been truncated isSignificandTruncated, final int the exponent number of the truncated significand exponentOfTruncatedSignificand)Tries to compute |
| pack-priv static double | Returns: the computed double on success,Double#NaN on failurewhether the number is negative isNegative, long uint64 the significand significand, int the exponent number (the power) power)Tries to compute |
| pack-priv static double | Returns: the double value, orDouble#NaN if the fast path failed.true if the sign is negative isNegative, long the significand significand, long the exponent number (the power) exponent, boolean true if significand has been truncated isSignificandTruncated, long the exponent number of the truncated significand exponentOfTruncatedSignificand)Tries to compute |
| DOUBLE_EXPONENT_BIAS | back to summary |
|---|---|
| public static final int DOUBLE_EXPONENT_BIAS Bias used in the exponent of a double. | |
| DOUBLE_MAX_EXPONENT_POWER_OF_TEN | back to summary |
|---|---|
| pack-priv static final int DOUBLE_MAX_EXPONENT_POWER_OF_TEN Largest power of 10 value of the exponent. Any number of form w * 10^309 where w >= 1 is going to be infinite in a double, so we never need to worry about powers of 10 greater than 308. | |
| DOUBLE_MAX_EXPONENT_POWER_OF_TWO | back to summary |
|---|---|
| private static final int DOUBLE_MAX_EXPONENT_POWER_OF_TWO | |
| DOUBLE_MIN_EXPONENT_POWER_OF_TEN | back to summary |
|---|---|
| pack-priv static final int DOUBLE_MIN_EXPONENT_POWER_OF_TEN Smallest power of 10 value of the exponent. The smallest non-zero double is 2^−1074. We take as input numbers of the form w x 10^q where w < 2^64. We have that w * 10^-343 < 2^(63-343) * 5^-343 < 2^-1076. However, we have that (2^64-1) * 10^-342 = (2^64 - 1) * 2^-342 * 5^-342 > 2^−1074. Thus, it is possible for a number of the form w * 10^-342 where w is a 64-bit value to be a non-zero double. ******** If we are solely interested in the *normal* numbers then the smallest value is 2^-1022. We can generate a value larger than 2^-1022 with expressions of the form w * 10^-326. Thus, we need to pick SMALLEST_POWER_OF_TEN >= -326. | |
| DOUBLE_MIN_EXPONENT_POWER_OF_TWO | back to summary |
|---|---|
| private static final int DOUBLE_MIN_EXPONENT_POWER_OF_TWO | |
| DOUBLE_POWERS_OF_TEN | back to summary |
|---|---|
| private static final double[] DOUBLE_POWERS_OF_TEN Precomputed powers of ten from 10^0 to 10^22. These can be represented exactly using the double type. | |
| DOUBLE_SIGNIFICAND_WIDTH | back to summary |
|---|---|
| public static final int DOUBLE_SIGNIFICAND_WIDTH The number of bits in the significand, including the implicit bit. | |
| MANTISSA_128 | back to summary |
|---|---|
| pack-priv static final long[] MANTISSA_128 A complement to mantissa_64 complete to a 128-bit mantissa. Uses about 5KB but is rarely accessed.
UInt128 getMantissa128(int q) {
return new UInt128(
MANTISSA_64[q - SMALLEST_POWER_OF_TEN],
MANTISSA_128[q - SMALLEST_POWER_OF_TEN];
);
}
| |
| MANTISSA_64 | back to summary |
|---|---|
| pack-priv static final long[] MANTISSA_64 When mapping numbers from decimal to binary, we go from w * 10^q to m * 2^p, but we have 10^q = 5^q * 2^q, so effectively we are trying to match w * 2^q * 5^q to m * 2^p. Thus, the powers of two are not a concern since they can be represented exactly using the binary notation, only the powers of five affect the binary significand. The mantissas of powers of ten from -308 to 308, extended out to sixty-four bits. The array contains the powers of ten approximated as a 64-bit mantissa. It goes from 10^-325 to 10^308 (inclusively). The mantissa is truncated, and never rounded up. Uses about 5 KB.
long getMantissaHigh(int q) {
MANTISSA_64[q - SMALLEST_POWER_OF_TEN];
}
| |
| FastDoubleMath | back to summary |
|---|---|
| private FastDoubleMath() Don't let anyone instantiate this class. | |
| tryDecFloatToDoubleTruncated | back to summary |
|---|---|
| pack-priv static double tryDecFloatToDoubleTruncated(boolean isNegative, long significand, int exponent, boolean isSignificandTruncated, final int exponentOfTruncatedSignificand) Tries to compute
| |
| tryDecToDoubleWithFastAlgorithm | back to summary |
|---|---|
| pack-priv static double tryDecToDoubleWithFastAlgorithm(boolean isNegative, long significand, int power) Tries to compute This function will only work in some cases, when it does not work it returns NaN. This should work *most of the time* (like 99% of the time). We assume that power is in the [-325, 308] interval: the caller is responsible for this check.
| |
| tryHexFloatToDoubleTruncated | back to summary |
|---|---|
| pack-priv static double tryHexFloatToDoubleTruncated(boolean isNegative, long significand, long exponent, boolean isSignificandTruncated, long exponentOfTruncatedSignificand) Tries to compute
| |