Refactor Number.prototype methods toFixed, toExponential, toPrecision (#3911)

JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
Szilagyi Adam
2020-07-21 12:46:03 +02:00
committed by GitHub
parent fee3c295a2
commit 2fac7cc85e
6 changed files with 255 additions and 642 deletions
@@ -34,6 +34,7 @@ assert((123456789012345678901.0).toExponential(20) === "1.23456789012345680000e+
assert((123456789012345678901.0).toExponential("6") === "1.234568e+20");
assert((123.45).toExponential(3.2) === "1.235e+2");
assert((123.45).toExponential(-0.1) === "1e+2");
assert((12).toExponential(21) === "1.200000000000000000000e+1")
try {
(12).toExponential(Number.MAX_VALUE);
@@ -56,13 +57,6 @@ try {
assert(e instanceof RangeError)
}
try {
(12).toExponential(21);
assert(false);
} catch (e) {
assert(e instanceof RangeError)
}
try {
Number.prototype.toExponential.call(new Object());
assert(false);
+6 -11
View File
@@ -33,15 +33,17 @@ assert((0.0).toFixed(0) === "0");
assert((0.0).toFixed(1) === "0.0");
assert((-0.0).toFixed(0) === "0");
assert((-0.0).toFixed(1) === "0.0");
assert((123456789012345678901.0).toFixed(20) === "123456789012345683968.00000000000000000000");
assert((123.56).toFixed(NaN) === "124");
assert((123.56).toFixed(-0.9) === "124");
assert((0.095).toFixed(2) === "0.10");
assert((0.995).toFixed(2) === "0.99");
assert((9.995).toFixed(2) === "9.99");
assert((0.995).toFixed(2) === "1.00")
assert((9.995).toFixed(2) === "10.00");
assert((7.995).toFixed(2) === "8.00");
assert((8.995).toFixed(2) === "8.99");
assert((8.995).toFixed(2) === "9.00");
assert((99.995).toFixed(2) === "100.00");
assert((12).toFixed(21) === "12.000000000000000000000");
assert((-1111111111111111111111.12).toFixed(3) === "-1.1111111111111111e+21");
assert((1111111111111111111111.12).toFixed(3) === "1.1111111111111111e+21");
try {
Number.prototype.toExponential.call(new Object());
@@ -57,13 +59,6 @@ try {
assert(e instanceof RangeError)
}
try {
(12).toFixed(21);
assert(false);
} catch (e) {
assert(e instanceof RangeError)
}
assert ((0.5).toFixed(0) === "1");
assert ((1.5).toFixed(0) === "2");
assert ((12.5).toFixed(0) === "13");
+5 -7
View File
@@ -32,9 +32,14 @@ assert((0.0).toPrecision(6) === "0.00000");
assert((123456789012345678901.0).toPrecision(20) === "1.2345678901234568000e+20");
assert((123456789012345678901.0).toPrecision(21) === "123456789012345680000");
assert((123456789012345678901.0).toPrecision("6") === "1.23457e+20");
assert((0.0000004).toPrecision(2) === "4.0e-7");
assert((0.000004).toPrecision(2) === "0.0000040");
assert((1234.92).toPrecision(4) === "1235");
assert((1234.92).toPrecision(3) === "1.23e+3");
assert((123.56).toPrecision(1.3) === "1e+2");
assert((123.56).toPrecision(21.9) === "123.560000000000000000");
assert((12).toPrecision(22) === "12.00000000000000000000")
assert(Number(982).toPrecision(1) === "1e+3");
assert(Number(982).toPrecision(2) === "9.8e+2");
@@ -48,13 +53,6 @@ try {
assert(e instanceof RangeError)
}
try {
(12).toPrecision(22);
assert(false);
} catch (e) {
assert(e instanceof RangeError)
}
try {
Number.prototype.toExponential.call(new Object());
assert(false);