OLD | NEW |
---|---|
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 assertEquals("1e-8", (0.00000001).toString()); | 48 assertEquals("1e-8", (0.00000001).toString()); |
49 assertEquals("1.2e-8", (0.000000012).toString()); | 49 assertEquals("1.2e-8", (0.000000012).toString()); |
50 assertEquals("1.23e-8", (0.0000000123).toString()); | 50 assertEquals("1.23e-8", (0.0000000123).toString()); |
51 | 51 |
52 assertEquals("0", (-0).toString()); | 52 assertEquals("0", (-0).toString()); |
53 assertEquals("-9", (-9).toString()); | 53 assertEquals("-9", (-9).toString()); |
54 assertEquals("-90", (-90).toString()); | 54 assertEquals("-90", (-90).toString()); |
55 assertEquals("-90.12", (-90.12).toString()); | 55 assertEquals("-90.12", (-90.12).toString()); |
56 assertEquals("-0.1", (-0.1).toString()); | 56 assertEquals("-0.1", (-0.1).toString()); |
57 assertEquals("-0.01", (-0.01).toString()); | 57 assertEquals("-0.01", (-0.01).toString()); |
58 assertEquals("-0.0123", (-0.0123).toString()) | 58 assertEquals("-0.0123", (-0.0123).toString()); |
59 assertEquals("-111111111111111110000", (-111111111111111111111).toString()); | 59 assertEquals("-111111111111111110000", (-111111111111111111111).toString()); |
60 assertEquals("-1.1111111111111111e+21", (-1111111111111111111111).toString()); | 60 assertEquals("-1.1111111111111111e+21", (-1111111111111111111111).toString()); |
61 assertEquals("-1.1111111111111111e+22", (-11111111111111111111111).toString()); | 61 assertEquals("-1.1111111111111111e+22", (-11111111111111111111111).toString()); |
62 assertEquals("-0.00001", (-0.00001).toString()); | 62 assertEquals("-0.00001", (-0.00001).toString()); |
63 assertEquals("-0.000001", (-0.000001).toString()); | 63 assertEquals("-0.000001", (-0.000001).toString()); |
64 assertEquals("-1e-7", (-0.0000001).toString()); | 64 assertEquals("-1e-7", (-0.0000001).toString()); |
65 assertEquals("-1.2e-7", (-0.00000012).toString()); | 65 assertEquals("-1.2e-7", (-0.00000012).toString()); |
66 assertEquals("-1.23e-7", (-0.000000123).toString()); | 66 assertEquals("-1.23e-7", (-0.000000123).toString()); |
67 assertEquals("-1e-8", (-0.00000001).toString()); | 67 assertEquals("-1e-8", (-0.00000001).toString()); |
68 assertEquals("-1.2e-8", (-0.000000012).toString()); | 68 assertEquals("-1.2e-8", (-0.000000012).toString()); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 assertEquals("10000000000000128.00", (10000000000000128).toFixed(2)); | 212 assertEquals("10000000000000128.00", (10000000000000128).toFixed(2)); |
213 assertEquals("10000000000000128.00000000000000000000", (10000000000000128).toFix ed(20)); | 213 assertEquals("10000000000000128.00000000000000000000", (10000000000000128).toFix ed(20)); |
214 assertEquals("0", (0).toFixed()); | 214 assertEquals("0", (0).toFixed()); |
215 assertEquals("-42.000", ((-42).toFixed(3))); | 215 assertEquals("-42.000", ((-42).toFixed(3))); |
216 assertEquals("-1000000000000000128", (-1000000000000000128).toFixed()); | 216 assertEquals("-1000000000000000128", (-1000000000000000128).toFixed()); |
217 assertEquals("-0.00000000000000000010", (-0.0000000000000000001).toFixed(20)); | 217 assertEquals("-0.00000000000000000010", (-0.0000000000000000001).toFixed(20)); |
218 assertEquals("0.12312312312312299889", (0.123123123123123).toFixed(20)); | 218 assertEquals("0.12312312312312299889", (0.123123123123123).toFixed(20)); |
219 // Test that we round up even when the last digit generated is even. | 219 // Test that we round up even when the last digit generated is even. |
220 // dtoa does not do this in its original form. | 220 // dtoa does not do this in its original form. |
221 assertEquals("1", 0.5.toFixed(0), "0.5.toFixed(0)"); | 221 assertEquals("1", 0.5.toFixed(0), "0.5.toFixed(0)"); |
222 assertEquals("-1", -0.5.toFixed(0), "-0.5.toFixed(0)"); | 222 assertEquals("-1", (-0.5).toFixed(0), "-0.5.toFixed(0)"); |
Søren Thygesen Gjesse
2011/04/15 10:20:51
() in the message string as well.
| |
223 assertEquals("1.3", 1.25.toFixed(1), "1.25.toFixed(1)"); | 223 assertEquals("1.3", 1.25.toFixed(1), "1.25.toFixed(1)"); |
224 // This is bizare, but Spidermonkey and KJS behave the same. | 224 // This is bizare, but Spidermonkey and KJS behave the same. |
225 assertEquals("234.2040", (234.20405).toFixed(4), "234.2040.toFixed(4)"); | 225 assertEquals("234.2040", (234.20405).toFixed(4), "234.2040.toFixed(4)"); |
226 assertEquals("234.2041", (234.2040506).toFixed(4)); | 226 assertEquals("234.2041", (234.2040506).toFixed(4)); |
227 | 227 |
228 // ---------------------------------------------------------------------- | 228 // ---------------------------------------------------------------------- |
229 // toExponential | 229 // toExponential |
230 assertEquals("1e+0", (1).toExponential()); | 230 assertEquals("1e+0", (1).toExponential()); |
231 assertEquals("1.1e+1", (11).toExponential()); | 231 assertEquals("1.1e+1", (11).toExponential()); |
232 assertEquals("1.12e+2", (112).toExponential()); | 232 assertEquals("1.12e+2", (112).toExponential()); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 assertEquals("-1.2e+4", Number(-12345).toPrecision(2)); | 331 assertEquals("-1.2e+4", Number(-12345).toPrecision(2)); |
332 assertEquals("-1.235e+4", Number(-12345.67).toPrecision(4)); | 332 assertEquals("-1.235e+4", Number(-12345.67).toPrecision(4)); |
333 assertEquals("-1.234e+4", Number(-12344.67).toPrecision(4)); | 333 assertEquals("-1.234e+4", Number(-12344.67).toPrecision(4)); |
334 // Test that we round up even when the last digit generated is even. | 334 // Test that we round up even when the last digit generated is even. |
335 // dtoa does not do this in its original form. | 335 // dtoa does not do this in its original form. |
336 assertEquals("1.3", 1.25.toPrecision(2), "1.25.toPrecision(2)"); | 336 assertEquals("1.3", 1.25.toPrecision(2), "1.25.toPrecision(2)"); |
337 assertEquals("1.4", 1.35.toPrecision(2), "1.35.toPrecision(2)"); | 337 assertEquals("1.4", 1.35.toPrecision(2), "1.35.toPrecision(2)"); |
338 | 338 |
339 | 339 |
340 | 340 |
OLD | NEW |