java.lang.Object
org.jfree.svg.util.RyuDouble

public final class RyuDoubleextends Object
An implementation of Ryu for double.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    Exponent bias of a double.
    private static final int
    Exponent bits of a double.
    private static final int
    Mask of the exponent bits.
    private static final int
    Mantissa bits of a double.
    private static final long
    Mask of the mantissa bits.
    private static final int
    Entries in the negative power of five table.
    private static final int
    Entries in the positive power of five table.
    private static final int
    Significant bits in a split power of five.
    private static final int
    Significant bits in a split inverse power.
    private static final int
    Bits in one quarter of a split inverse.
    private static final int[][]
    Table of the negative powers of five.
    private static final int
    Bits in one quarter of a split power.
    private static final int[][]
    Table of the positive powers of five.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a Ryu instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static int
    decimalLength(long v)
    Counts the decimal digits of a value.
    static String
    doubleToString(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 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.
    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.
    private static boolean
    multipleOfPowerOf5(long value, int q)
    Checks whether a value divides the power of five.
    private static int
    pow5bits(int e)
    Estimates the bit count of a power of five.
    private static int
    pow5Factor(long value)
    Counts the factors of five in a value.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DOUBLE_MANTISSA_BITS

      private static final int DOUBLE_MANTISSA_BITS
      Mantissa bits of a double.
      See Also:
    • DOUBLE_MANTISSA_MASK

      private static final long DOUBLE_MANTISSA_MASK
      Mask of the mantissa bits.
      See Also:
    • DOUBLE_EXPONENT_BITS

      private static final int DOUBLE_EXPONENT_BITS
      Exponent bits of a double.
      See Also:
    • DOUBLE_EXPONENT_MASK

      private static final int DOUBLE_EXPONENT_MASK
      Mask of the exponent bits.
      See Also:
    • DOUBLE_EXPONENT_BIAS

      private static final int DOUBLE_EXPONENT_BIAS
      Exponent bias of a double.
      See Also:
    • POS_TABLE_SIZE

      private static final int POS_TABLE_SIZE
      Entries in the positive power of five table.
      See Also:
    • NEG_TABLE_SIZE

      private static final int NEG_TABLE_SIZE
      Entries in the negative power of five table.
      See Also:
    • POW5_BITCOUNT

      private static final int POW5_BITCOUNT
      Significant bits in a split power of five.
      See Also:
    • POW5_QUARTER_BITCOUNT

      private static final int POW5_QUARTER_BITCOUNT
      Bits in one quarter of a split power.
      See Also:
    • POW5_SPLIT

      private static final int[][] POW5_SPLIT
      Table of the positive powers of five.
    • POW5_INV_BITCOUNT

      private static final int POW5_INV_BITCOUNT
      Significant bits in a split inverse power.
      See Also:
    • POW5_INV_QUARTER_BITCOUNT

      private static final int POW5_INV_QUARTER_BITCOUNT
      Bits in one quarter of a split inverse.
      See Also:
    • POW5_INV_SPLIT

      private static final int[][] POW5_INV_SPLIT
      Table of the negative powers of five.
  • Constructor Details

    • RyuDouble

      public RyuDouble()
      Creates a Ryu instance.
  • Method Details

    • doubleToString

      public static String doubleToString(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.
      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 check
      q - 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 bits
      i - the POW5_SPLIT row selecting the power of 5
      j - 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 bits
      i - the POW5_INV_SPLIT row selecting the inverse power of 5
      j - the total right shift in bits
      Returns:
      the high digits of m / 5^i / 2^j