Reviewed by Sam.
[WebKit-https.git] / LayoutTests / fast / js / resources / number-toExponential.js
1 var posInf = 1/0;
2 var negInf = -1/0;
3 var nan = 0/0;
4
5 // From Acid3, http://bugs.webkit.org/show_bug.cgi?id=16640
6 shouldBeEqualToString("(0.0).toExponential(4)", "0.0000e+0");
7 shouldBeEqualToString("(-0.0).toExponential(4)", "0.0000e+0");
8 shouldBeEqualToString("(0.0).toExponential()", "0e+0");
9 shouldBeEqualToString("(-0.0).toExponential()", "0e+0");
10 // From http://bugs.webkit.org/show_bug.cgi?id=5259
11 shouldBeEqualToString("(123.456).toExponential()", "1.23456e+2");
12 shouldBeEqualToString("(123.456).toExponential(0)", "1e+2");
13 // 0 equivilents
14 shouldBeEqualToString("(123.456).toExponential(null)", "1e+2");
15 shouldBeEqualToString("(123.456).toExponential(false)", "1e+2");
16 shouldBeEqualToString("(123.456).toExponential('foo')", "1e+2");
17 shouldBeEqualToString("(123.456).toExponential(nan)", "1e+2"); // nan is treated like 0
18
19 shouldBeEqualToString("(123.456).toExponential(1)", "1.2e+2");
20 // 1 equivilents
21 shouldBeEqualToString("(123.456).toExponential(true)", "1.2e+2"); // just like 1
22 shouldBeEqualToString("(123.456).toExponential('1')", "1.2e+2");
23
24 shouldBeEqualToString("(123.456).toExponential(2)", "1.23e+2");
25 shouldBeEqualToString("(123.456).toExponential(2.9)", "1.23e+2");
26 shouldBeEqualToString("(123.456).toExponential(3)", "1.235e+2");
27 shouldBeEqualToString("(123.456).toExponential(5)", "1.23456e+2");
28 shouldBeEqualToString("(123.456).toExponential(6)", "1.234560e+2");
29 shouldBeEqualToString("(123.456).toExponential(20)", "1.23456000000000003070e+2");
30
31 // SpiderMonkey allows precision values 0 to 100, we only allow 0 to 20 currently
32 shouldBeEqualToString("(123.456).toExponential(21)", "1.234560000000000030695e+2");
33 shouldBeEqualToString("(123.456).toExponential(100)", "1.2345600000000000306954461848363280296325683593750000000000000000000000000000000000000000000000000000e+2");
34 shouldThrow("(123.456).toExponential(101)");
35 shouldThrow("(123.456).toExponential(-1)");
36
37 shouldThrow("(1234.567).toExponential(posInf)");
38 shouldThrow("(1234.567).toExponential(negInf)");
39
40 shouldBeEqualToString("posInf.toExponential()", "Infinity");
41 shouldBeEqualToString("negInf.toExponential()", "-Infinity");
42 shouldBeEqualToString("nan.toExponential()", "NaN");
43
44 var successfullyParsed = true;