From c246bb6e1e04847413308c97b6f9b03b77606c85 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 21 Nov 2017 01:23:44 +0300 Subject: [PATCH] Fix code that represents doubles as text in bootstrap mode --- .../java/lang/TAbstractStringBuilder.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java index 0abedbff9..fed2b9762 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java @@ -19,14 +19,14 @@ import org.teavm.classlib.java.io.TSerializable; import org.teavm.classlib.java.util.TArrays; class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequence { - private static final float[] powersOfTen = { 1E1f, 1E2f, 1E4f, 1E8f, 1E16f, 1E32f }; - private static final double[] doublePowersOfTen = { 1E1, 1E2, 1E4, 1E8, 1E16, 1E32, 1E64, 1E128, 1E256 }; - private static final float[] negPowersOfTen = { 1E-1f, 1E-2f, 1E-4f, 1E-8f, 1E-16f, 1E-32f }; - private static final double[] negDoublePowersOfTen = { 1E-1, 1E-2, 1E-4, 1E-8, 1E-16, 1E-32, + private static float[] powersOfTen = { 1E1f, 1E2f, 1E4f, 1E8f, 1E16f, 1E32f }; + private static double[] doublePowersOfTen = { 1E1, 1E2, 1E4, 1E8, 1E16, 1E32, 1E64, 1E128, 1E256 }; + private static float[] negPowersOfTen = { 1E-1f, 1E-2f, 1E-4f, 1E-8f, 1E-16f, 1E-32f }; + private static double[] negDoublePowersOfTen = { 1E-1, 1E-2, 1E-4, 1E-8, 1E-16, 1E-32, 1E-64, 1E-128, 1E-256 }; - private static final int[] intPowersOfTen = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, + private static int[] intPowersOfTen = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; - private static final long[] longPowersOfTen = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, + private static long[] longPowersOfTen = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000L, 100000000000L, 1000000000000L, 10000000000000L, 100000000000000L, 1000000000000000L, 10000000000000000L, 100000000000000000L, 1000000000000000000L }; private static final long[] longLogPowersOfTen = { 1, 10, 100, 10000, 100000000, 10000000000000000L, }; @@ -264,6 +264,11 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ } exp = -exp; mantissa = (int) (((value * FLOAT_MAX_POS) / digit) + 0.5f); + + while (mantissa >= 10000000) { + mantissa /= 10; + exp--; + } } // Remove trailing zeros @@ -418,6 +423,11 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ } exp = -exp; mantissa = (long) (((value * DOUBLE_MAX_POS) / digit) + 0.5); + + while (mantissa >= 10000000000000000L) { + mantissa /= 10; + exp--; + } } // Remove trailing zeros