mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
parent
0485930c1f
commit
52a23fcadd
|
@ -83,27 +83,30 @@ public class TDouble extends TNumber implements TComparable<TDouble> {
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
char c = string.charAt(index);
|
char c = string.charAt(index);
|
||||||
if (c < '0' || c > '9') {
|
|
||||||
throw new TNumberFormatException();
|
|
||||||
}
|
|
||||||
long mantissa = 0;
|
long mantissa = 0;
|
||||||
int exp = 0;
|
int exp = 0;
|
||||||
while (string.charAt(index) == '0') {
|
if (c != '.') {
|
||||||
if (++index == string.length()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (index < string.length()) {
|
|
||||||
c = string.charAt(index);
|
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
break;
|
throw new TNumberFormatException();
|
||||||
}
|
}
|
||||||
if (mantissa < 1E17) {
|
while (string.charAt(index) == '0') {
|
||||||
mantissa = mantissa * 10 + (c - '0');
|
if (++index == string.length()) {
|
||||||
} else {
|
return 0;
|
||||||
++exp;
|
}
|
||||||
|
}
|
||||||
|
while (index < string.length()) {
|
||||||
|
c = string.charAt(index);
|
||||||
|
if (c < '0' || c > '9') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (mantissa < 1E17) {
|
||||||
|
mantissa = mantissa * 10 + (c - '0');
|
||||||
|
} else {
|
||||||
|
++exp;
|
||||||
|
}
|
||||||
|
++index;
|
||||||
}
|
}
|
||||||
++index;
|
|
||||||
}
|
}
|
||||||
if (index < string.length() && string.charAt(index) == '.') {
|
if (index < string.length() && string.charAt(index) == '.') {
|
||||||
++index;
|
++index;
|
||||||
|
|
|
@ -117,28 +117,33 @@ public class TFloat extends TNumber implements TComparable<TFloat> {
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
char c = string.charAt(index);
|
char c = string.charAt(index);
|
||||||
if (c < '0' || c > '9') {
|
|
||||||
throw new TNumberFormatException();
|
|
||||||
}
|
|
||||||
int mantissa = 0;
|
int mantissa = 0;
|
||||||
int exp = 0;
|
int exp = 0;
|
||||||
while (string.charAt(index) == '0') {
|
if (c != '.') {
|
||||||
if (++index == string.length()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (index < string.length()) {
|
|
||||||
c = string.charAt(index);
|
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
break;
|
throw new TNumberFormatException();
|
||||||
}
|
}
|
||||||
if (mantissa < 1E8) {
|
|
||||||
mantissa = mantissa * 10 + (c - '0');
|
while (string.charAt(index) == '0') {
|
||||||
} else {
|
if (++index == string.length()) {
|
||||||
++exp;
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (index < string.length()) {
|
||||||
|
c = string.charAt(index);
|
||||||
|
if (c < '0' || c > '9') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (mantissa < 1E8) {
|
||||||
|
mantissa = mantissa * 10 + (c - '0');
|
||||||
|
} else {
|
||||||
|
++exp;
|
||||||
|
}
|
||||||
|
++index;
|
||||||
}
|
}
|
||||||
++index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index < string.length() && string.charAt(index) == '.') {
|
if (index < string.length() && string.charAt(index) == '.') {
|
||||||
++index;
|
++index;
|
||||||
boolean hasOneDigit = false;
|
boolean hasOneDigit = false;
|
||||||
|
|
|
@ -34,6 +34,7 @@ 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(0.1, Double.parseDouble(".1"), 0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -25,28 +25,30 @@ import org.teavm.junit.TeaVMTestRunner;
|
||||||
public class FloatTest {
|
public class FloatTest {
|
||||||
@Test
|
@Test
|
||||||
public void parsed() {
|
public void parsed() {
|
||||||
assertEquals(23, Double.parseDouble("23"), 1E-12);
|
assertEquals(23, Float.parseFloat("23"), 1E-12F);
|
||||||
assertEquals(23, Double.parseDouble("23.0"), 1E-12);
|
assertEquals(23, Float.parseFloat("23.0"), 1E-12F);
|
||||||
assertEquals(23, Double.parseDouble("23E0"), 1E-12);
|
assertEquals(23, Float.parseFloat("23E0"), 1E-12F);
|
||||||
assertEquals(23, Double.parseDouble("2.30000E1"), 1E-12);
|
assertEquals(23, Float.parseFloat("2.30000E1"), 1E-12F);
|
||||||
assertEquals(23, Double.parseDouble("0.23E2"), 1E-12);
|
assertEquals(23, Float.parseFloat("0.23E2"), 1E-12F);
|
||||||
assertEquals(23, Double.parseDouble("0.000023E6"), 1E-12);
|
assertEquals(23, Float.parseFloat("0.000023E6"), 1E-12F);
|
||||||
assertEquals(23, Double.parseDouble("00230000e-4"), 1E-12);
|
assertEquals(23, Float.parseFloat("00230000e-4"), 1E-12F);
|
||||||
assertEquals(23, Double.parseDouble("2300000000000000000000e-20"), 1E-12);
|
assertEquals(23, Float.parseFloat("2300000000000000000000e-20"), 1E-12F);
|
||||||
assertEquals(23, Double.parseDouble("2300000000000000000000e-20"), 1E-12);
|
assertEquals(23, Float.parseFloat("2300000000000000000000e-20"), 1E-12F);
|
||||||
|
assertEquals(23, Float.parseFloat("2300000000000000000000e-20"), 1E-12F);
|
||||||
|
assertEquals(0.1F, Float.parseFloat("0.1"), 0.001F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void negativeParsed() {
|
public void negativeParsed() {
|
||||||
assertEquals(-23, Double.parseDouble("-23"), 1E-12);
|
assertEquals(-23, Float.parseFloat("-23"), 1E-12F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void zeroParsed() {
|
public void zeroParsed() {
|
||||||
assertEquals(0, Double.parseDouble("0.0"), 1E-12);
|
assertEquals(0, Float.parseFloat("0.0"), 1E-12F);
|
||||||
assertEquals(0, Double.parseDouble("23E-8000"), 1E-12);
|
assertEquals(0, Float.parseFloat("23E-8000"), 1E-12F);
|
||||||
assertEquals(0, Double.parseDouble("00000"), 1E-12);
|
assertEquals(0, Float.parseFloat("00000"), 1E-12F);
|
||||||
assertEquals(0, Double.parseDouble("00000.0000"), 1E-12);
|
assertEquals(0, Float.parseFloat("00000.0000"), 1E-12F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue
Block a user