OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 17 matching lines...) Expand all Loading... |
28 // Flags: --max-new-space-size=256 | 28 // Flags: --max-new-space-size=256 |
29 | 29 |
30 function zero() { | 30 function zero() { |
31 var x = 0.5; | 31 var x = 0.5; |
32 return (function() { return x - 0.5; })(); | 32 return (function() { return x - 0.5; })(); |
33 } | 33 } |
34 | 34 |
35 function test() { | 35 function test() { |
36 assertEquals(0, Math.abs(0)); | 36 assertEquals(0, Math.abs(0)); |
37 assertEquals(0, Math.abs(zero())); | 37 assertEquals(0, Math.abs(zero())); |
38 assertEquals(1/0, 1/Math.abs(-0)); // 0 == -0, so we use reciprocals. | 38 assertEquals(0, Math.abs(-0)); |
39 assertEquals(Infinity, Math.abs(Infinity)); | 39 assertEquals(Infinity, Math.abs(Infinity)); |
40 assertEquals(Infinity, Math.abs(-Infinity)); | 40 assertEquals(Infinity, Math.abs(-Infinity)); |
41 assertNaN(Math.abs(NaN)); | 41 assertEquals(NaN, Math.abs(NaN)); |
42 assertNaN(Math.abs(-NaN)); | 42 assertEquals(NaN, Math.abs(-NaN)); |
43 assertEquals('Infinity', Math.abs(Number('+Infinity').toString())); | 43 assertEquals('Infinity', Math.abs(Number('+Infinity')).toString()); |
44 assertEquals('Infinity', Math.abs(Number('-Infinity').toString())); | 44 assertEquals('Infinity', Math.abs(Number('-Infinity')).toString()); |
45 assertEquals('NaN', Math.abs(NaN).toString()); | 45 assertEquals('NaN', Math.abs(NaN).toString()); |
46 assertEquals('NaN', Math.abs(-NaN).toString()); | 46 assertEquals('NaN', Math.abs(-NaN).toString()); |
47 | 47 |
48 assertEquals(0.1, Math.abs(0.1)); | 48 assertEquals(0.1, Math.abs(0.1)); |
49 assertEquals(0.5, Math.abs(0.5)); | 49 assertEquals(0.5, Math.abs(0.5)); |
50 assertEquals(0.1, Math.abs(-0.1)); | 50 assertEquals(0.1, Math.abs(-0.1)); |
51 assertEquals(0.5, Math.abs(-0.5)); | 51 assertEquals(0.5, Math.abs(-0.5)); |
52 assertEquals(1, Math.abs(1)); | 52 assertEquals(1, Math.abs(1)); |
53 assertEquals(1.1, Math.abs(1.1)); | 53 assertEquals(1.1, Math.abs(1.1)); |
54 assertEquals(1.5, Math.abs(1.5)); | 54 assertEquals(1.5, Math.abs(1.5)); |
(...skipping 23 matching lines...) Expand all Loading... |
78 | 78 |
79 assertEquals(two_31, Math.abs(two_31)); | 79 assertEquals(two_31, Math.abs(two_31)); |
80 assertEquals(two_31, Math.abs(-two_31)); | 80 assertEquals(two_31, Math.abs(-two_31)); |
81 | 81 |
82 assertEquals(two_31 + 1, Math.abs(two_31 + 1)); | 82 assertEquals(two_31 + 1, Math.abs(two_31 + 1)); |
83 assertEquals(two_31 + 1, Math.abs(-two_31 - 1)); | 83 assertEquals(two_31 + 1, Math.abs(-two_31 - 1)); |
84 | 84 |
85 assertEquals(two_31 - 1, Math.abs(two_31 - 1)); | 85 assertEquals(two_31 - 1, Math.abs(two_31 - 1)); |
86 assertEquals(two_31 - 1, Math.abs(-two_31 + 1)); | 86 assertEquals(two_31 - 1, Math.abs(-two_31 + 1)); |
87 | 87 |
88 assertNaN(Math.abs("not a number")); | 88 assertEquals(NaN, Math.abs("not a number")); |
89 assertNaN(Math.abs([1, 2, 3])); | 89 assertEquals(NaN, Math.abs([1, 2, 3])); |
90 assertEquals(42, Math.abs({valueOf: function() { return 42; } })); | 90 assertEquals(42, Math.abs({valueOf: function() { return 42; } })); |
91 assertEquals(42, Math.abs({valueOf: function() { return -42; } })); | 91 assertEquals(42, Math.abs({valueOf: function() { return -42; } })); |
92 } | 92 } |
93 | 93 |
94 | 94 |
95 // Test in a loop to cover the custom IC and GC-related issues. | 95 // Test in a loop to cover the custom IC and GC-related issues. |
96 for (var i = 0; i < 500; i++) { | 96 for (var i = 0; i < 500; i++) { |
97 test(); | 97 test(); |
98 } | 98 } |
OLD | NEW |