diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java index bc9464aea..329c42b3e 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java @@ -121,7 +121,7 @@ public class TDouble extends TNumber implements TComparable { if (c < '0' || c > '9') { break; } - if (mantissa < 1E17) { + if (mantissa < TLong.MAX_VALUE / 10 - 9) { mantissa = mantissa * 10 + (c - '0'); } else { ++exp; @@ -136,7 +136,7 @@ public class TDouble extends TNumber implements TComparable { if (c < '0' || c > '9') { break; } - if (mantissa < 1E17) { + if (mantissa < TLong.MAX_VALUE / 10 - 9) { mantissa = mantissa * 10 + (c - '0'); --exp; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java index 8961b9f83..d5d5a1d9c 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java @@ -167,7 +167,7 @@ public class TFloat extends TNumber implements TComparable { if (c < '0' || c > '9') { break; } - if (mantissa < 1E8) { + if (mantissa < (TInteger.MAX_VALUE / 10) - 9) { mantissa = mantissa * 10 + (c - '0'); } else { ++exp; @@ -183,7 +183,7 @@ public class TFloat extends TNumber implements TComparable { if (c < '0' || c > '9') { break; } - if (mantissa < 1E38) { + if (mantissa < (TInteger.MAX_VALUE / 10) - 9) { mantissa = mantissa * 10 + (c - '0'); --exp; } diff --git a/tests/src/test/java/org/teavm/classlib/java/lang/DoubleTest.java b/tests/src/test/java/org/teavm/classlib/java/lang/DoubleTest.java index 348768869..4bd0e4087 100644 --- a/tests/src/test/java/org/teavm/classlib/java/lang/DoubleTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/lang/DoubleTest.java @@ -49,6 +49,9 @@ public class DoubleTest { assertEquals(0, Double.parseDouble("23E-8000"), 1E-12); assertEquals(0, Double.parseDouble("00000"), 1E-12); assertEquals(0, Double.parseDouble("00000.0000"), 1E-12); + + assertEquals(4499999999999888888888888.0, Double.parseDouble("4499999999999888888888888"), 1E9); + assertEquals(0.4499999999999888888888888, Double.parseDouble("0.4499999999999888888888888"), 1E-15); } @Test diff --git a/tests/src/test/java/org/teavm/classlib/java/lang/FloatTest.java b/tests/src/test/java/org/teavm/classlib/java/lang/FloatTest.java index 1824984bb..4690f17bd 100644 --- a/tests/src/test/java/org/teavm/classlib/java/lang/FloatTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/lang/FloatTest.java @@ -50,6 +50,8 @@ public class FloatTest { assertEquals(0, Float.parseFloat("23E-8000"), 1E-12F); assertEquals(0, Float.parseFloat("00000"), 1E-12F); assertEquals(0, Float.parseFloat("00000.0000"), 1E-12F); + assertEquals(4499999285F, Float.parseFloat("4499999285"), 100F); + assertEquals(0.4499999285F, Float.parseFloat("0.4499999285"), 1E-9F); } @Test