mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fix Float/Double.parse for strings like '123.'
This commit is contained in:
parent
f080526aca
commit
6900fd587c
|
@ -87,7 +87,9 @@ public class TDouble extends TNumber implements TComparable<TDouble> {
|
||||||
|
|
||||||
long mantissa = 0;
|
long mantissa = 0;
|
||||||
int exp = 0;
|
int exp = 0;
|
||||||
|
boolean hasOneDigit = false;
|
||||||
if (c != '.') {
|
if (c != '.') {
|
||||||
|
hasOneDigit = true;
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
throw new TNumberFormatException();
|
throw new TNumberFormatException();
|
||||||
}
|
}
|
||||||
|
@ -111,7 +113,6 @@ public class TDouble extends TNumber implements TComparable<TDouble> {
|
||||||
}
|
}
|
||||||
if (index < string.length() && string.charAt(index) == '.') {
|
if (index < string.length() && string.charAt(index) == '.') {
|
||||||
++index;
|
++index;
|
||||||
boolean hasOneDigit = false;
|
|
||||||
while (index < string.length()) {
|
while (index < string.length()) {
|
||||||
c = string.charAt(index);
|
c = string.charAt(index);
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
|
@ -142,7 +143,7 @@ public class TDouble extends TNumber implements TComparable<TDouble> {
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
int numExp = 0;
|
int numExp = 0;
|
||||||
boolean hasOneDigit = false;
|
hasOneDigit = false;
|
||||||
while (index < string.length()) {
|
while (index < string.length()) {
|
||||||
c = string.charAt(index);
|
c = string.charAt(index);
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
|
|
|
@ -120,7 +120,10 @@ public class TFloat extends TNumber implements TComparable<TFloat> {
|
||||||
|
|
||||||
int mantissa = 0;
|
int mantissa = 0;
|
||||||
int exp = 0;
|
int exp = 0;
|
||||||
|
|
||||||
|
boolean hasOneDigit = false;
|
||||||
if (c != '.') {
|
if (c != '.') {
|
||||||
|
hasOneDigit = true;
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
throw new TNumberFormatException();
|
throw new TNumberFormatException();
|
||||||
}
|
}
|
||||||
|
@ -146,7 +149,6 @@ public class TFloat extends TNumber implements TComparable<TFloat> {
|
||||||
|
|
||||||
if (index < string.length() && string.charAt(index) == '.') {
|
if (index < string.length() && string.charAt(index) == '.') {
|
||||||
++index;
|
++index;
|
||||||
boolean hasOneDigit = false;
|
|
||||||
while (index < string.length()) {
|
while (index < string.length()) {
|
||||||
c = string.charAt(index);
|
c = string.charAt(index);
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
|
@ -177,7 +179,7 @@ public class TFloat extends TNumber implements TComparable<TFloat> {
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
int numExp = 0;
|
int numExp = 0;
|
||||||
boolean hasOneDigit = false;
|
hasOneDigit = false;
|
||||||
while (index < string.length()) {
|
while (index < string.length()) {
|
||||||
c = string.charAt(index);
|
c = string.charAt(index);
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
|
|
|
@ -34,6 +34,8 @@ public class DoubleTest {
|
||||||
assertEquals(23, Double.parseDouble("00230000e-4"), 1E-12);
|
assertEquals(23, Double.parseDouble("00230000e-4"), 1E-12);
|
||||||
assertEquals(23, Double.parseDouble("2300000000000000000000e-20"), 1E-12);
|
assertEquals(23, Double.parseDouble("2300000000000000000000e-20"), 1E-12);
|
||||||
assertEquals(23, Double.parseDouble("2300000000000000000000e-20"), 1E-12);
|
assertEquals(23, Double.parseDouble("2300000000000000000000e-20"), 1E-12);
|
||||||
|
assertEquals(23, Double.parseDouble("23."), 1E-12);
|
||||||
|
assertEquals(0.1, Double.parseDouble("0.1"), 0.001);
|
||||||
assertEquals(0.1, Double.parseDouble(".1"), 0.001);
|
assertEquals(0.1, Double.parseDouble(".1"), 0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,9 @@ public class FloatTest {
|
||||||
assertEquals(23, Float.parseFloat("2300000000000000000000e-20"), 1E-12F);
|
assertEquals(23, Float.parseFloat("2300000000000000000000e-20"), 1E-12F);
|
||||||
assertEquals(23, Float.parseFloat("2300000000000000000000e-20"), 1E-12F);
|
assertEquals(23, Float.parseFloat("2300000000000000000000e-20"), 1E-12F);
|
||||||
assertEquals(23, Float.parseFloat("2300000000000000000000e-20"), 1E-12F);
|
assertEquals(23, Float.parseFloat("2300000000000000000000e-20"), 1E-12F);
|
||||||
|
assertEquals(23, Float.parseFloat("23."), 1E-12F);
|
||||||
assertEquals(0.1F, Float.parseFloat("0.1"), 0.001F);
|
assertEquals(0.1F, Float.parseFloat("0.1"), 0.001F);
|
||||||
|
assertEquals(0.1F, Float.parseFloat(".1"), 0.001F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -37,7 +37,6 @@ class TeaVMProcessHandler extends ProcessHandler implements DevServerRunnerListe
|
||||||
void start() throws IOException {
|
void start() throws IOException {
|
||||||
info = DevServerRunner.start(DaemonUtil.detectClassPath().toArray(new String[0]), config, this);
|
info = DevServerRunner.start(DaemonUtil.detectClassPath().toArray(new String[0]), config, this);
|
||||||
console.setServerManager(info.server);
|
console.setServerManager(info.server);
|
||||||
startNotify();
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> info.process.destroy()));
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> info.process.destroy()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user