java.lang.Object
org.jfree.svg.util.RyuDouble
An implementation of Ryu for double.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intExponent bias of a double.private static final intExponent bits of a double.private static final intMask of the exponent bits.private static final intMantissa bits of a double.private static final longMask of the mantissa bits.private static final intEntries in the negative power of five table.private static final intEntries in the positive power of five table.private static final intSignificant bits in a split power of five.private static final intSignificant bits in a split inverse power.private static final intBits in one quarter of a split inverse.private static final int[][]Table of the negative powers of five.private static final intBits in one quarter of a split power.private static final int[][]Table of the positive powers of five.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate static intdecimalLength(long v) Counts the decimal digits of a value.static StringdoubleToString(double value, int decimals) Converts a double value to its shortest decimal representation using the Ryu algorithm, rounded to the specified number of decimal places.private static longmulPow5divPow2(long m, int i, int j) Compute the high digits of m * 5^p / 10^q = m * 5^(p - q) / 2^q = m * 5^i / 2^j, with q chosen such that m * 5^i / 2^j has sufficiently many decimal digits to represent the original floating point number.private static longmulPow5InvDivPow2(long m, int i, int j) Compute the high digits of m / 5^i / 2^j such that the result is accurate to at least 9 decimal digits.private static booleanmultipleOfPowerOf5(long value, int q) Checks whether a value divides the power of five.private static intpow5bits(int e) Estimates the bit count of a power of five.private static intpow5Factor(long value) Counts the factors of five in a value.
Field Details
DOUBLE_MANTISSA_BITS
private static final int DOUBLE_MANTISSA_BITSMantissa bits of a double.- See Also:
DOUBLE_MANTISSA_MASK
private static final long DOUBLE_MANTISSA_MASKMask of the mantissa bits.- See Also:
DOUBLE_EXPONENT_BITS
private static final int DOUBLE_EXPONENT_BITSExponent bits of a double.- See Also:
DOUBLE_EXPONENT_MASK
private static final int DOUBLE_EXPONENT_MASKMask of the exponent bits.- See Also:
DOUBLE_EXPONENT_BIAS
private static final int DOUBLE_EXPONENT_BIASExponent bias of a double.- See Also:
POS_TABLE_SIZE
private static final int POS_TABLE_SIZEEntries in the positive power of five table.- See Also:
NEG_TABLE_SIZE
private static final int NEG_TABLE_SIZEEntries in the negative power of five table.- See Also:
POW5_BITCOUNT
private static final int POW5_BITCOUNTSignificant bits in a split power of five.- See Also:
POW5_QUARTER_BITCOUNT
private static final int POW5_QUARTER_BITCOUNTBits in one quarter of a split power.- See Also:
POW5_SPLIT
private static final int[][] POW5_SPLITTable of the positive powers of five.POW5_INV_BITCOUNT
private static final int POW5_INV_BITCOUNTSignificant bits in a split inverse power.- See Also:
POW5_INV_QUARTER_BITCOUNT
private static final int POW5_INV_QUARTER_BITCOUNTBits in one quarter of a split inverse.- See Also:
POW5_INV_SPLIT
private static final int[][] POW5_INV_SPLITTable of the negative powers of five.
Constructor Details
RyuDouble
public RyuDouble()Creates a Ryu instance.
Method Details
doubleToString
Converts a double value to its shortest decimal representation using the Ryu algorithm, rounded to the specified number of decimal places.- Parameters:
value- the double value to convert.decimals- the number of decimal places to round to.- Returns:
- A string representation of the double value.
pow5bits
private static int pow5bits(int e) Estimates the bit count of a power of five.- Parameters:
e- the exponent of the power- Returns:
- the number of significant bits
decimalLength
private static int decimalLength(long v) Counts the decimal digits of a value.- Parameters:
v- the value to measure- Returns:
- the number of digits
multipleOfPowerOf5
private static boolean multipleOfPowerOf5(long value, int q) Checks whether a value divides the power of five.- Parameters:
value- the value to checkq- the exponent of the power- Returns:
- true if the value is a multiple
pow5Factor
private static int pow5Factor(long value) Counts the factors of five in a value.- Parameters:
value- the value to factor- Returns:
- the number of five factors
mulPow5divPow2
private static long mulPow5divPow2(long m, int i, int j) Compute the high digits of m * 5^p / 10^q = m * 5^(p - q) / 2^q = m * 5^i / 2^j, with q chosen such that m * 5^i / 2^j has sufficiently many decimal digits to represent the original floating point number.- Parameters:
m- the value to multiply, at most 55 bitsi- the POW5_SPLIT row selecting the power of 5j- the total right shift in bits- Returns:
- the high digits of m * 5^i / 2^j
mulPow5InvDivPow2
private static long mulPow5InvDivPow2(long m, int i, int j) Compute the high digits of m / 5^i / 2^j such that the result is accurate to at least 9 decimal digits. i and j are already chosen appropriately.- Parameters:
m- the value to multiply, at most 55 bitsi- the POW5_INV_SPLIT row selecting the inverse power of 5j- the total right shift in bits- Returns:
- the high digits of m / 5^i / 2^j