From 0a92994c4b880f2ac449e9da063e6ec435e31df9 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 14 Sep 2023 10:04:27 +0200 Subject: [PATCH] classlib: improve accuracy of double parser and fix possible issue --- .../java/org/teavm/classlib/impl/text/DoubleAnalyzer.java | 4 ---- .../java/org/teavm/classlib/impl/text/DoubleSynthesizer.java | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/classlib/src/main/java/org/teavm/classlib/impl/text/DoubleAnalyzer.java b/classlib/src/main/java/org/teavm/classlib/impl/text/DoubleAnalyzer.java index 6b583dd1f..075a2226f 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/text/DoubleAnalyzer.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/text/DoubleAnalyzer.java @@ -134,10 +134,6 @@ public final class DoubleAnalyzer { long c = (c3 << (32 + shift)) + (c2 << (16 + shift)) + (c1 << shift); cm += c0 << 16; - // TODO: removing this gives better result in random tests, however toString(1.0) gives '0.5' - if (((cm >>> (31 - shift)) & 1) != 0) { - ++c; - } c += cm >>> (32 - shift); return c; diff --git a/classlib/src/main/java/org/teavm/classlib/impl/text/DoubleSynthesizer.java b/classlib/src/main/java/org/teavm/classlib/impl/text/DoubleSynthesizer.java index 6b8c7461c..d20cd61c9 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/text/DoubleSynthesizer.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/text/DoubleSynthesizer.java @@ -39,6 +39,10 @@ public final class DoubleSynthesizer { return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } binMantissa += 1L << 4; + if ((binMantissa & (-1L << 58L)) != 0) { + binMantissa >>>= 1; + binExp++; + } if (binExp <= 0) { binMantissa >>= Math.min(-binExp + 1, 64); binExp = 0;