From d844d1cc1d71b52f14bc6d7a2e4a7118e9063767 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Thu, 19 Dec 2013 22:05:11 +0400 Subject: [PATCH] Double decimal representation test passes --- .../teavm/classlib/java/lang/TAbstractStringBuilder.java | 6 +++--- .../org/teavm/classlib/java/lang/StringBuilderTest.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java index 59471d8c5..8a4e4394c 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java @@ -25,7 +25,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ private static final int FLOAT_DECIMAL_PRECISION = 7; private static final int DOUBLE_DECIMAL_PRECISION = 16; private static final float FLOAT_DECIMAL_FACTOR = 1E6f; - private static final double DOUBLE_DECIMAL_FACTOR = 1E15f; + private static final double DOUBLE_DECIMAL_FACTOR = 1E15; private static final int FLOAT_MAX_EXPONENT = 38; private static final int DOUBLE_MAX_EXPONENT = 308; private static final int FLOAT_MAX_POS = 1000000; @@ -331,7 +331,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ } bit >>= 1; } - mantissa = (long)((value / (digit / DOUBLE_DECIMAL_FACTOR)) + 0.5f); + mantissa = (long)(((value / digit) * DOUBLE_DECIMAL_FACTOR) + 0.5); } else { ++sz; int bit = 256; @@ -449,7 +449,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ int result = 0; int bit = 16; for (int i = longLogPowersOfTen.length - 1; i >= 0; --i) { - if (n % zeros == 0) { + if (n % (zeros * longLogPowersOfTen[i]) == 0) { result |= bit; zeros *= longLogPowersOfTen[i]; } diff --git a/teavm-classlib/src/test/java/org/teavm/classlib/java/lang/StringBuilderTest.java b/teavm-classlib/src/test/java/org/teavm/classlib/java/lang/StringBuilderTest.java index a7cb5d611..05678f8d5 100644 --- a/teavm-classlib/src/test/java/org/teavm/classlib/java/lang/StringBuilderTest.java +++ b/teavm-classlib/src/test/java/org/teavm/classlib/java/lang/StringBuilderTest.java @@ -193,8 +193,8 @@ public class StringBuilderTest { @Test public void doubleAppended() { StringBuilder sb = new StringBuilder(); - sb.append(1.2345678E150); - assertEquals("1.2345678E150", sb.toString()); + sb.append(1.23456789E150); + assertEquals("1.23456789E150", sb.toString()); } @Test