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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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)); | 147 assertEquals("1.1", (4/3).toString(3)); |
148 assertEquals("11.1", (13/3).toString(3)); | 148 assertEquals("11.1", (13/3).toString(3)); |
149 assertEquals("0.01", (1/9).toString(3)); | 149 assertEquals("0.01", (1/9).toString(3)); |
150 assertEquals("10000", (81).toString(3)); | 150 assertEquals("10000", (81).toString(3)); |
151 assertEquals("10000.01", (81 + 1/9).toString(3)); | 151 assertEquals("10000.01", (81 + 1/9).toString(3)); |
152 assertEquals("0.0212010212010212010212010212010212", (2/7).toString(3)); | 152 assertEquals("0.0212010212010212010212010212010212", (2/7).toString(3)); |
153 | 153 |
| 154 assertEquals("314404114120101444444424000000000000000", |
| 155 (1.2345e+27).toString(5)); |
| 156 |
154 // ---------------------------------------------------------------------- | 157 // ---------------------------------------------------------------------- |
155 // toFixed | 158 // toFixed |
156 assertEquals("NaN", (NaN).toFixed(2)); | 159 assertEquals("NaN", (NaN).toFixed(2)); |
157 assertEquals("Infinity", (1/0).toFixed(2)); | 160 assertEquals("Infinity", (1/0).toFixed(2)); |
158 assertEquals("-Infinity", (-1/0).toFixed(2)); | 161 assertEquals("-Infinity", (-1/0).toFixed(2)); |
159 | 162 |
160 assertEquals("1.1111111111111111e+21", (1111111111111111111111).toFixed(8)); | 163 assertEquals("1.1111111111111111e+21", (1111111111111111111111).toFixed(8)); |
161 assertEquals("0.1", (0.1).toFixed(1)); | 164 assertEquals("0.1", (0.1).toFixed(1)); |
162 assertEquals("0.10", (0.1).toFixed(2)); | 165 assertEquals("0.10", (0.1).toFixed(2)); |
163 assertEquals("0.100", (0.1).toFixed(3)); | 166 assertEquals("0.100", (0.1).toFixed(3)); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 assertEquals("-12", Number(-12.345).toPrecision(2)); | 338 assertEquals("-12", Number(-12.345).toPrecision(2)); |
336 assertEquals("-1.2e+2", Number(-123.45).toPrecision(2)); | 339 assertEquals("-1.2e+2", Number(-123.45).toPrecision(2)); |
337 assertEquals("-1.2e+3", Number(-1234.5).toPrecision(2)); | 340 assertEquals("-1.2e+3", Number(-1234.5).toPrecision(2)); |
338 assertEquals("-1.2e+4", Number(-12345).toPrecision(2)); | 341 assertEquals("-1.2e+4", Number(-12345).toPrecision(2)); |
339 assertEquals("-1.235e+4", Number(-12345.67).toPrecision(4)); | 342 assertEquals("-1.235e+4", Number(-12345.67).toPrecision(4)); |
340 assertEquals("-1.234e+4", Number(-12344.67).toPrecision(4)); | 343 assertEquals("-1.234e+4", Number(-12344.67).toPrecision(4)); |
341 // Test that we round up even when the last digit generated is even. | 344 // Test that we round up even when the last digit generated is even. |
342 // dtoa does not do this in its original form. | 345 // dtoa does not do this in its original form. |
343 assertEquals("1.3", 1.25.toPrecision(2), "1.25.toPrecision(2)"); | 346 assertEquals("1.3", 1.25.toPrecision(2), "1.25.toPrecision(2)"); |
344 assertEquals("1.4", 1.35.toPrecision(2), "1.35.toPrecision(2)"); | 347 assertEquals("1.4", 1.35.toPrecision(2), "1.35.toPrecision(2)"); |
OLD | NEW |