Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / v8 / test / mjsunit / number-tostring-small.js
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
4 // met:
5 //
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.
15 //
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.
27
28 // This file is a concatenation of the number-tostring and
29 // to-precision mjsunit tests where the mjsunit assert code has been
30 // removed.
31
32 // ----------------------------------------------------------------------
33 // toString
34 (NaN).toString();
35 (1/0).toString();
36 (-1/0).toString();
37 (0).toString();
38 (9).toString();
39 (90).toString();
40 (90.12).toString();
41 (0.1).toString();
42 (0.01).toString();
43 (0.0123).toString();
44 (111111111111111111111).toString();
45 (1111111111111111111111).toString();
46 (11111111111111111111111).toString();
47 (0.00001).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();
55
56 (-0).toString();
57 (-9).toString();
58 (-90).toString();
59 (-90.12).toString();
60 (-0.1).toString();
61 (-0.01).toString();
62 (-0.0123).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();
74
75 (NaN).toString(16);
76 (1/0).toString(16);
77 (-1/0).toString(16);
78 (0).toString(16);
79 (9).toString(16);
80 (90).toString(16);
81 (90.12).toString(16);
82 (0.1).toString(16);
83 (0.01).toString(16);
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);
96
97 (-0).toString(16);
98 (-9).toString(16);
99 (-90).toString(16);
100 (-90.12).toString(16);
101 (-0.1).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);
115
116 (2,32).toString();
117 (Math.pow(2,32)-1).toString(16);
118 (Math.pow(2,32)-1).toString(2);
119 (10000007).toString(36);
120 (0).toString(36);
121 (0).toString(16);
122 (0).toString(10);
123 (0).toString(8);
124 (0).toString(2);
125 (2,32).toString(2);
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);
136 (1000).toString();
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();
146 (8.5).toString(16);
147 (-8.5).toString(16);
148
149 // ----------------------------------------------------------------------
150 // toFixed
151 (NaN).toFixed(2);
152 (1/0).toFixed(2);
153 (-1/0).toFixed(2);
154
155 (1111111111111111111111).toFixed(8);
156 (0.1).toFixed(1);
157 (0.1).toFixed(2);
158 (0.1).toFixed(3);
159 (0.01).toFixed(2);
160 (0.01).toFixed(3);
161 (0.01).toFixed(4);
162 (0.001).toFixed(2);
163 (0.001).toFixed(3);
164 (0.001).toFixed(4);
165 (1).toFixed(4);
166 (1).toFixed(1);
167 (1).toFixed(0);
168 (12).toFixed(0);
169 (1.1).toFixed(0);
170 (12.1).toFixed(0);
171 (1.12).toFixed(0);
172 (12.12).toFixed(0);
173 (0.0000006).toFixed(7);
174 (0.00000006).toFixed(8);
175 (0.00000006).toFixed(9);
176 (0.00000006).toFixed(10);
177 (0).toFixed(0);
178 (0).toFixed(1);
179 (0).toFixed(2);
180
181 (-1111111111111111111111).toFixed(8);
182 (-0.1).toFixed(1);
183 (-0.1).toFixed(2);
184 (-0.1).toFixed(3);
185 (-0.01).toFixed(2);
186 (-0.01).toFixed(3);
187 (-0.01).toFixed(4);
188 (-0.001).toFixed(2);
189 (-0.001).toFixed(3);
190 (-0.001).toFixed(4);
191 (-1).toFixed(4);
192 (-1).toFixed(1);
193 (-1).toFixed(0);
194 (-1.1).toFixed(0);
195 (-12.1).toFixed(0);
196 (-1.12).toFixed(0);
197 (-12.12).toFixed(0);
198 (-0.0000006).toFixed(7);
199 (-0.00000006).toFixed(8);
200 (-0.00000006).toFixed(9);
201 (-0.00000006).toFixed(10);
202 (-0).toFixed(0);
203 (-0).toFixed(1);
204 (-0).toFixed(2);
205
206 (1000).toFixed();
207 (0.00001).toFixed();
208 (0.00001).toFixed(5);
209 (0.0000000000000000001).toFixed(20);
210 (0.00001).toFixed(17);
211 (1).toFixed(17);
212 (1000000000000000128).toFixed();
213 (100000000000000128).toFixed(1);
214 (10000000000000128).toFixed(2);
215 (10000000000000128).toFixed(20);
216 (0).toFixed();
217 ((-42).toFixed(3));
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.
223 (0.5).toFixed(0);
224 (-0.5).toFixed(0);
225 (1.25).toFixed(1);
226 // This is bizare, but Spidermonkey and KJS behave the same.
227 (234.20405).toFixed(4);
228 (234.2040506).toFixed(4);
229
230 // ----------------------------------------------------------------------
231 // toExponential
232 (1).toExponential();
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);
262
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);
293
294 (NaN).toExponential(2);
295 (Infinity).toExponential(2);
296 (-Infinity).toExponential(2);
297 (1).toExponential(0);
298 (0).toExponential();
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();
306
307 // ----------------------------------------------------------------------
308 // toPrecision
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);
340
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);
349
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);
357
358
359 // Test the fixed notation output.
360 (7).toPrecision(1);
361 (7).toPrecision(2);
362 (7).toPrecision(3);
363
364 (-7).toPrecision(1);
365 (-7).toPrecision(2);
366 (-7).toPrecision(3);
367
368 (91).toPrecision(1);
369 (91).toPrecision(2);
370 (91).toPrecision(3);
371 (91).toPrecision(4);
372
373 (-91).toPrecision(1);
374 (-91).toPrecision(2);
375 (-91).toPrecision(3);
376 (-91).toPrecision(4);
377
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);
386
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);