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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 assertEquals("1e+21", (1000000000000000012800).toString()); | 137 assertEquals("1e+21", (1000000000000000012800).toString()); |
138 assertEquals("-1e+21", (-1000000000000000012800).toString()); | 138 assertEquals("-1e+21", (-1000000000000000012800).toString()); |
139 assertEquals("1e-7", (0.0000001).toString()); | 139 assertEquals("1e-7", (0.0000001).toString()); |
140 assertEquals("-1e-7", (-0.0000001).toString()); | 140 assertEquals("-1e-7", (-0.0000001).toString()); |
141 assertEquals("1.0000000000000001e+21", (1000000000000000128000).toString()); | 141 assertEquals("1.0000000000000001e+21", (1000000000000000128000).toString()); |
142 assertEquals("0.000001", (0.000001).toString()); | 142 assertEquals("0.000001", (0.000001).toString()); |
143 assertEquals("1e-7", (0.0000001).toString()); | 143 assertEquals("1e-7", (0.0000001).toString()); |
144 assertEquals("8.8", (8.5).toString(16)); | 144 assertEquals("8.8", (8.5).toString(16)); |
145 assertEquals("-8.8", (-8.5).toString(16)); | 145 assertEquals("-8.8", (-8.5).toString(16)); |
146 | 146 |
| 147 assertEquals("1.1", (4/3).toString(3)); |
| 148 assertEquals("11.1", (13/3).toString(3)); |
| 149 assertEquals("0.01", (1/9).toString(3)); |
| 150 assertEquals("10000", (81).toString(3)); |
| 151 assertEquals("10000.01", (81 + 1/9).toString(3)); |
| 152 assertEquals("0.0212010212010212010212010212010212", (2/7).toString(3)); |
| 153 |
147 // ---------------------------------------------------------------------- | 154 // ---------------------------------------------------------------------- |
148 // toFixed | 155 // toFixed |
149 assertEquals("NaN", (NaN).toFixed(2)); | 156 assertEquals("NaN", (NaN).toFixed(2)); |
150 assertEquals("Infinity", (1/0).toFixed(2)); | 157 assertEquals("Infinity", (1/0).toFixed(2)); |
151 assertEquals("-Infinity", (-1/0).toFixed(2)); | 158 assertEquals("-Infinity", (-1/0).toFixed(2)); |
152 | 159 |
153 assertEquals("1.1111111111111111e+21", (1111111111111111111111).toFixed(8)); | 160 assertEquals("1.1111111111111111e+21", (1111111111111111111111).toFixed(8)); |
154 assertEquals("0.1", (0.1).toFixed(1)); | 161 assertEquals("0.1", (0.1).toFixed(1)); |
155 assertEquals("0.10", (0.1).toFixed(2)); | 162 assertEquals("0.10", (0.1).toFixed(2)); |
156 assertEquals("0.100", (0.1).toFixed(3)); | 163 assertEquals("0.100", (0.1).toFixed(3)); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 assertEquals("-12", Number(-12.345).toPrecision(2)); | 335 assertEquals("-12", Number(-12.345).toPrecision(2)); |
329 assertEquals("-1.2e+2", Number(-123.45).toPrecision(2)); | 336 assertEquals("-1.2e+2", Number(-123.45).toPrecision(2)); |
330 assertEquals("-1.2e+3", Number(-1234.5).toPrecision(2)); | 337 assertEquals("-1.2e+3", Number(-1234.5).toPrecision(2)); |
331 assertEquals("-1.2e+4", Number(-12345).toPrecision(2)); | 338 assertEquals("-1.2e+4", Number(-12345).toPrecision(2)); |
332 assertEquals("-1.235e+4", Number(-12345.67).toPrecision(4)); | 339 assertEquals("-1.235e+4", Number(-12345.67).toPrecision(4)); |
333 assertEquals("-1.234e+4", Number(-12344.67).toPrecision(4)); | 340 assertEquals("-1.234e+4", Number(-12344.67).toPrecision(4)); |
334 // Test that we round up even when the last digit generated is even. | 341 // Test that we round up even when the last digit generated is even. |
335 // dtoa does not do this in its original form. | 342 // dtoa does not do this in its original form. |
336 assertEquals("1.3", 1.25.toPrecision(2), "1.25.toPrecision(2)"); | 343 assertEquals("1.3", 1.25.toPrecision(2), "1.25.toPrecision(2)"); |
337 assertEquals("1.4", 1.35.toPrecision(2), "1.35.toPrecision(2)"); | 344 assertEquals("1.4", 1.35.toPrecision(2), "1.35.toPrecision(2)"); |
OLD | NEW |