Class DoubleAnalyzer

java.lang.Object
dev.gmitch215.bytebox.text.DoubleAnalyzer

public final class DoubleAnalyzer extends Object
The class library's DoubleAnalyzer (TeaVM 0.15.0, org.teavm.classlib.impl.text), with its choice of digits replaced.

This is what Double.toString, String.valueOf(double), string concatenation and StringBuilder.append(double) write digits from. The original multiplies by a 64-bit table entry and drops low bits, so the 18-digit value it finds and the two edges of the interval of decimals that read back as the same double are each a few units of the last digit low. A candidate that close to an edge, or two candidates that close to a tie, are picked wrongly: it wrote text that read back as a different double, or not the shortest. A subnormal it shifted up to a full significand, which made the interval as narrow as a normal one's, so it wrote 4.940656458412465E-324 where a JVM writes 4.9E-324.

The table arithmetic stays as the fast path, with how far it can be off written down: below the exact figure by less than four units, never above. The choice is made from it when it would be the same for every figure within that; otherwise, and for every subnormal, Exact works the digits out without error.

Found through Substitutions. It is a copy because a substitute replaces the class under its own name and cannot call the original, and the tables are what the original is made of.

  • Field Details

  • Method Details

    • fastIntLog10

      public static int fastIntLog10(double d)
    • analyze

      public static void analyze(double d, DoubleAnalyzer.Result result)
    • mulAndShiftRight

      public static long mulAndShiftRight(long a, long b, int shift)