1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 // This file is a concatenation of the number-tostring and
29 // to-precision mjsunit tests where the mjsunit assert code has been
32 // ----------------------------------------------------------------------
44 (111111111111111111111).toString();
45 (1111111111111111111111).toString();
46 (11111111111111111111111).toString();
48 (0.000001).toString();
49 (0.0000001).toString();
50 (0.00000012).toString();
51 (0.000000123).toString();
52 (0.00000001).toString();
53 (0.000000012).toString();
54 (0.0000000123).toString();
63 (-111111111111111111111).toString();
64 (-1111111111111111111111).toString();
65 (-11111111111111111111111).toString();
66 (-0.00001).toString();
67 (-0.000001).toString();
68 (-0.0000001).toString();
69 (-0.00000012).toString();
70 (-0.000000123).toString();
71 (-0.00000001).toString();
72 (-0.000000012).toString();
73 (-0.0000000123).toString();
84 (0.0123).toString(16);
85 (111111111111111111111).toString(16);
86 (1111111111111111111111).toString(16);
87 (11111111111111111111111).toString(16);
88 (0.00001).toString(16);
89 (0.000001).toString(16);
90 (0.0000001).toString(16);
91 (0.00000012).toString(16);
92 (0.000000123).toString(16);
93 (0.00000001).toString(16);
94 (0.000000012).toString(16);
95 (0.0000000123).toString(16);
100 (-90.12).toString(16);
102 (-0.01).toString(16);
103 (-0.0123).toString(16);
104 (-111111111111111111111).toString(16);
105 (-1111111111111111111111).toString(16);
106 (-11111111111111111111111).toString(16);
107 (-0.00001).toString(16);
108 (-0.000001).toString(16);
109 (-0.0000001).toString(16);
110 (-0.00000012).toString(16);
111 (-0.000000123).toString(16);
112 (-0.00000001).toString(16);
113 (-0.000000012).toString(16);
114 (-0.0000000123).toString(16);
117 (Math.pow(2,32)-1).toString(16);
118 (Math.pow(2,32)-1).toString(2);
119 (10000007).toString(36);
126 (Math.pow(2,32) + 1).toString(2);
127 (0x100000000000081).toString(16);
128 (-(-'0x1000000000000081')).toString(16);
129 (0x100000000000081).toString(2);
130 (-(Math.pow(2,32)-1)).toString(2);
131 (-10000007).toString(36);
132 (-Math.pow(2,32)).toString(2);
133 (-(Math.pow(2,32) + 1)).toString(2);
134 (-0x100000000000081).toString(16);
135 (-0x100000000000081).toString(2);
137 (0.00001).toString();
138 (1000000000000000128).toString();
139 (1000000000000000012800).toString();
140 (-1000000000000000012800).toString();
141 (0.0000001).toString();
142 (-0.0000001).toString();
143 (1000000000000000128000).toString();
144 (0.000001).toString();
145 (0.0000001).toString();
149 // ----------------------------------------------------------------------
155 (1111111111111111111111).toFixed(8);
173 (0.0000006).toFixed(7);
174 (0.00000006).toFixed(8);
175 (0.00000006).toFixed(9);
176 (0.00000006).toFixed(10);
181 (-1111111111111111111111).toFixed(8);
198 (-0.0000006).toFixed(7);
199 (-0.00000006).toFixed(8);
200 (-0.00000006).toFixed(9);
201 (-0.00000006).toFixed(10);
208 (0.00001).toFixed(5);
209 (0.0000000000000000001).toFixed(20);
210 (0.00001).toFixed(17);
212 (1000000000000000128).toFixed();
213 (100000000000000128).toFixed(1);
214 (10000000000000128).toFixed(2);
215 (10000000000000128).toFixed(20);
218 (-1000000000000000128).toFixed();
219 (-0.0000000000000000001).toFixed(20);
220 (0.123123123123123).toFixed(20);
221 // Test that we round up even when the last digit generated is even.
222 // dtoa does not do this in its original form.
226 // This is bizare, but Spidermonkey and KJS behave the same.
227 (234.20405).toFixed(4);
228 (234.2040506).toFixed(4);
230 // ----------------------------------------------------------------------
233 (11).toExponential();
234 (112).toExponential();
235 (1).toExponential(0);
236 (11).toExponential(0);
237 (112).toExponential(0);
238 (1).toExponential(1);
239 (11).toExponential(1);
240 (112).toExponential(1);
241 (1).toExponential(2);
242 (11).toExponential(2);
243 (112).toExponential(2);
244 (1).toExponential(3);
245 (11).toExponential(3);
246 (112).toExponential(3);
247 (0.1).toExponential();
248 (0.11).toExponential();
249 (0.112).toExponential();
250 (0.1).toExponential(0);
251 (0.11).toExponential(0);
252 (0.112).toExponential(0);
253 (0.1).toExponential(1);
254 (0.11).toExponential(1);
255 (0.112).toExponential(1);
256 (0.1).toExponential(2);
257 (0.11).toExponential(2);
258 (0.112).toExponential(2);
259 (0.1).toExponential(3);
260 (0.11).toExponential(3);
261 (0.112).toExponential(3);
263 (-1).toExponential();
264 (-11).toExponential();
265 (-112).toExponential();
266 (-1).toExponential(0);
267 (-11).toExponential(0);
268 (-112).toExponential(0);
269 (-1).toExponential(1);
270 (-11).toExponential(1);
271 (-112).toExponential(1);
272 (-1).toExponential(2);
273 (-11).toExponential(2);
274 (-112).toExponential(2);
275 (-1).toExponential(3);
276 (-11).toExponential(3);
277 (-112).toExponential(3);
278 (-0.1).toExponential();
279 (-0.11).toExponential();
280 (-0.112).toExponential();
281 (-0.1).toExponential(0);
282 (-0.11).toExponential(0);
283 (-0.112).toExponential(0);
284 (-0.1).toExponential(1);
285 (-0.11).toExponential(1);
286 (-0.112).toExponential(1);
287 (-0.1).toExponential(2);
288 (-0.11).toExponential(2);
289 (-0.112).toExponential(2);
290 (-0.1).toExponential(3);
291 (-0.11).toExponential(3);
292 (-0.112).toExponential(3);
294 (NaN).toExponential(2);
295 (Infinity).toExponential(2);
296 (-Infinity).toExponential(2);
297 (1).toExponential(0);
299 (0).toExponential(2);
300 (11.2356).toExponential(0);
301 (11.2356).toExponential(4);
302 (0.000112356).toExponential(4);
303 (-0.000112356).toExponential(4);
304 (0.000112356).toExponential();
305 (-0.000112356).toExponential();
307 // ----------------------------------------------------------------------
309 (NaN).toPrecision(1);
310 (Infinity).toPrecision(2);
311 (-Infinity).toPrecision(2);
312 (0.000555).toPrecision(15);
313 (0.000000555).toPrecision(15);
314 (-0.000000555).toPrecision(15);
315 (123456789).toPrecision(1);
316 (123456789).toPrecision(9);
317 (123456789).toPrecision(8);
318 (123456789).toPrecision(7);
319 (-123456789).toPrecision(7);
320 (-.0000000012345).toPrecision(2);
321 (-.000000012345).toPrecision(2);
322 (-.00000012345).toPrecision(2);
323 (-.0000012345).toPrecision(2);
324 (-.000012345).toPrecision(2);
325 (-.00012345).toPrecision(2);
326 (-.0012345).toPrecision(2);
327 (-.012345).toPrecision(2);
328 (-.12345).toPrecision(2);
329 (-1.2345).toPrecision(2);
330 (-12.345).toPrecision(2);
331 (-123.45).toPrecision(2);
332 (-1234.5).toPrecision(2);
333 (-12345).toPrecision(2);
334 (-12345.67).toPrecision(4);
335 Number(-12344.67).toPrecision(4);
336 // Test that we round up even when the last digit generated is even.
337 // dtoa does not do this in its original form.
338 (1.25).toPrecision(2);
339 (1.35).toPrecision(2);
341 // Test the exponential notation output.
342 (1.2345e+27).toPrecision(1);
343 (1.2345e+27).toPrecision(2);
344 (1.2345e+27).toPrecision(3);
345 (1.2345e+27).toPrecision(4);
346 (1.2345e+27).toPrecision(5);
347 (1.2345e+27).toPrecision(6);
348 (1.2345e+27).toPrecision(7);
350 (-1.2345e+27).toPrecision(1);
351 (-1.2345e+27).toPrecision(2);
352 (-1.2345e+27).toPrecision(3);
353 (-1.2345e+27).toPrecision(4);
354 (-1.2345e+27).toPrecision(5);
355 (-1.2345e+27).toPrecision(6);
356 (-1.2345e+27).toPrecision(7);
359 // Test the fixed notation output.
373 (-91).toPrecision(1);
374 (-91).toPrecision(2);
375 (-91).toPrecision(3);
376 (-91).toPrecision(4);
378 (91.1234).toPrecision(1);
379 (91.1234).toPrecision(2);
380 (91.1234).toPrecision(3);
381 (91.1234).toPrecision(4);
382 (91.1234).toPrecision(5);
383 (91.1234).toPrecision(6);
384 (91.1234).toPrecision(7);
385 (91.1234).toPrecision(8);
387 (-91.1234).toPrecision(1);
388 (-91.1234).toPrecision(2);
389 (-91.1234).toPrecision(3);
390 (-91.1234).toPrecision(4);
391 (-91.1234).toPrecision(5);
392 (-91.1234).toPrecision(6);
393 (-91.1234).toPrecision(7);
394 (-91.1234).toPrecision(8);