Fix Float/Double.parse for strings like '123.'

This commit is contained in:
Alexey Andreev 2018-12-24 18:15:56 +03:00
parent f080526aca
commit 6900fd587c
5 changed files with 11 additions and 5 deletions

View File

@ -87,7 +87,9 @@ public class TDouble extends TNumber implements TComparable<TDouble> {
long mantissa = 0;
int exp = 0;
boolean hasOneDigit = false;
if (c != '.') {
hasOneDigit = true;
if (c < '0' || c > '9') {
throw new TNumberFormatException();
}
@ -111,7 +113,6 @@ public class TDouble extends TNumber implements TComparable<TDouble> {
}
if (index < string.length() && string.charAt(index) == '.') {
++index;
boolean hasOneDigit = false;
while (index < string.length()) {
c = string.charAt(index);
if (c < '0' || c > '9') {
@ -142,7 +143,7 @@ public class TDouble extends TNumber implements TComparable<TDouble> {
++index;
}
int numExp = 0;
boolean hasOneDigit = false;
hasOneDigit = false;
while (index < string.length()) {
c = string.charAt(index);
if (c < '0' || c > '9') {

View File

@ -120,7 +120,10 @@ public class TFloat extends TNumber implements TComparable<TFloat> {
int mantissa = 0;
int exp = 0;
boolean hasOneDigit = false;
if (c != '.') {
hasOneDigit = true;
if (c < '0' || c > '9') {
throw new TNumberFormatException();
}
@ -146,7 +149,6 @@ public class TFloat extends TNumber implements TComparable<TFloat> {
if (index < string.length() && string.charAt(index) == '.') {
++index;
boolean hasOneDigit = false;
while (index < string.length()) {
c = string.charAt(index);
if (c < '0' || c > '9') {
@ -177,7 +179,7 @@ public class TFloat extends TNumber implements TComparable<TFloat> {
++index;
}
int numExp = 0;
boolean hasOneDigit = false;
hasOneDigit = false;
while (index < string.length()) {
c = string.charAt(index);
if (c < '0' || c > '9') {

View File

@ -34,6 +34,8 @@ public class DoubleTest {
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("23."), 1E-12);
assertEquals(0.1, Double.parseDouble("0.1"), 0.001);
assertEquals(0.1, Double.parseDouble(".1"), 0.001);
}

View File

@ -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("23."), 1E-12F);
assertEquals(0.1F, Float.parseFloat("0.1"), 0.001F);
assertEquals(0.1F, Float.parseFloat(".1"), 0.001F);
}
@Test

View File

@ -37,7 +37,6 @@ class TeaVMProcessHandler extends ProcessHandler implements DevServerRunnerListe
void start() throws IOException {
info = DevServerRunner.start(DaemonUtil.detectClassPath().toArray(new String[0]), config, this);
console.setServerManager(info.server);
startNotify();
Runtime.getRuntime().addShutdownHook(new Thread(() -> info.process.destroy()));
}