mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fix Float.parse and Double.parse for some values
This commit is contained in:
parent
1785d6ad9e
commit
74cc1d8d7d
|
@ -121,7 +121,7 @@ public class TDouble extends TNumber implements TComparable<TDouble> {
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mantissa < 1E17) {
|
if (mantissa < TLong.MAX_VALUE / 10 - 9) {
|
||||||
mantissa = mantissa * 10 + (c - '0');
|
mantissa = mantissa * 10 + (c - '0');
|
||||||
} else {
|
} else {
|
||||||
++exp;
|
++exp;
|
||||||
|
@ -136,7 +136,7 @@ public class TDouble extends TNumber implements TComparable<TDouble> {
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mantissa < 1E17) {
|
if (mantissa < TLong.MAX_VALUE / 10 - 9) {
|
||||||
mantissa = mantissa * 10 + (c - '0');
|
mantissa = mantissa * 10 + (c - '0');
|
||||||
--exp;
|
--exp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ public class TFloat extends TNumber implements TComparable<TFloat> {
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mantissa < 1E8) {
|
if (mantissa < (TInteger.MAX_VALUE / 10) - 9) {
|
||||||
mantissa = mantissa * 10 + (c - '0');
|
mantissa = mantissa * 10 + (c - '0');
|
||||||
} else {
|
} else {
|
||||||
++exp;
|
++exp;
|
||||||
|
@ -183,7 +183,7 @@ public class TFloat extends TNumber implements TComparable<TFloat> {
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mantissa < 1E38) {
|
if (mantissa < (TInteger.MAX_VALUE / 10) - 9) {
|
||||||
mantissa = mantissa * 10 + (c - '0');
|
mantissa = mantissa * 10 + (c - '0');
|
||||||
--exp;
|
--exp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,9 @@ public class DoubleTest {
|
||||||
assertEquals(0, Double.parseDouble("23E-8000"), 1E-12);
|
assertEquals(0, Double.parseDouble("23E-8000"), 1E-12);
|
||||||
assertEquals(0, Double.parseDouble("00000"), 1E-12);
|
assertEquals(0, Double.parseDouble("00000"), 1E-12);
|
||||||
assertEquals(0, Double.parseDouble("00000.0000"), 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
|
@Test
|
||||||
|
|
|
@ -50,6 +50,8 @@ public class FloatTest {
|
||||||
assertEquals(0, Float.parseFloat("23E-8000"), 1E-12F);
|
assertEquals(0, Float.parseFloat("23E-8000"), 1E-12F);
|
||||||
assertEquals(0, Float.parseFloat("00000"), 1E-12F);
|
assertEquals(0, Float.parseFloat("00000"), 1E-12F);
|
||||||
assertEquals(0, Float.parseFloat("00000.0000"), 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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue
Block a user