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 498b5a17b..ee3d6e04c 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 @@ -249,7 +249,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ exp = 0; float digit = 1; for (int i = powersOfTen.length - 1; i >= 0; --i) { - if ((exp | bit) <= FLOAT_MAX_EXPONENT && powersOfTen[i] * digit < value) { + if ((exp | bit) <= FLOAT_MAX_EXPONENT && powersOfTen[i] * digit <= value) { digit *= powersOfTen[i]; exp |= bit; } @@ -290,7 +290,6 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ exp = 0; } } - sz += digits; // Extend buffer to store exponent if (exp != 0) { @@ -303,6 +302,11 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ } } + if (exp != 0 && digits == intPart) { + digits++; + } + sz += digits; + // Print mantissa insertSpace(target, target + sz); if (negative) { @@ -399,7 +403,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ exp = 0; double digit = 1; for (int i = doublePowersOfTen.length - 1; i >= 0; --i) { - if ((exp | bit) <= DOUBLE_MAX_EXPONENT && doublePowersOfTen[i] * digit < value) { + if ((exp | bit) <= DOUBLE_MAX_EXPONENT && doublePowersOfTen[i] * digit <= value) { digit *= doublePowersOfTen[i]; exp |= bit; } @@ -440,7 +444,6 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ exp = 0; } } - sz += digits; // Extend buffer to store exponent if (exp != 0) { @@ -456,6 +459,11 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ } } + if (exp != 0 && digits == intPart) { + digits++; + } + sz += digits; + // Print mantissa insertSpace(target, target + sz); if (negative) { diff --git a/teavm-classlib/src/test/java/org/teavm/classlib/impl/unicode/UnicodeSupportTest.java b/teavm-classlib/src/test/java/org/teavm/classlib/impl/unicode/UnicodeSupportTest.java index 802e0e123..4ff1315ea 100644 --- a/teavm-classlib/src/test/java/org/teavm/classlib/impl/unicode/UnicodeSupportTest.java +++ b/teavm-classlib/src/test/java/org/teavm/classlib/impl/unicode/UnicodeSupportTest.java @@ -1,9 +1,24 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.teavm.classlib.impl.unicode; import static org.junit.Assert.assertFalse; +import org.junit.Test; public class UnicodeSupportTest { - private static boolean pairsEqual(final int[] pairs, final int index1, final int index2) { return pairs[index1] == pairs[index2] && pairs[index1 + 1] == pairs[index2 + 1]; } @@ -16,5 +31,4 @@ public class UnicodeSupportTest { assertFalse(pairsEqual(digitValues, digitValues.length - 4, digitValues.length - 2)); } } - }