OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 20 matching lines...) Expand all Loading... |
31 function testRound(expect, input) { | 31 function testRound(expect, input) { |
32 // Make source code different on each invocation to make | 32 // Make source code different on each invocation to make |
33 // sure it gets optimized each time. | 33 // sure it gets optimized each time. |
34 var doRound = new Function('input', | 34 var doRound = new Function('input', |
35 '"' + (test_id++) + '";return Math.round(input)'); | 35 '"' + (test_id++) + '";return Math.round(input)'); |
36 assertEquals(expect, doRound(input)); | 36 assertEquals(expect, doRound(input)); |
37 assertEquals(expect, doRound(input)); | 37 assertEquals(expect, doRound(input)); |
38 assertEquals(expect, doRound(input)); | 38 assertEquals(expect, doRound(input)); |
39 %OptimizeFunctionOnNextCall(doRound); | 39 %OptimizeFunctionOnNextCall(doRound); |
40 assertEquals(expect, doRound(input)); | 40 assertEquals(expect, doRound(input)); |
| 41 |
| 42 // Force the Math.round() representation to double to exercise the associated |
| 43 // optimized code. |
| 44 var doRoundToDouble = new Function('input', |
| 45 '"' + (test_id++) + '";return Math.round(in
put) + -0.0'); |
| 46 assertEquals(expect, doRoundToDouble(input)); |
| 47 assertEquals(expect, doRoundToDouble(input)); |
| 48 assertEquals(expect, doRoundToDouble(input)); |
| 49 %OptimizeFunctionOnNextCall(doRoundToDouble); |
| 50 assertEquals(expect, doRoundToDouble(input)); |
41 } | 51 } |
42 | 52 |
43 testRound(0, 0); | 53 testRound(0, 0); |
44 testRound(-0, -0); | 54 testRound(-0, -0); |
45 testRound(Infinity, Infinity); | 55 testRound(Infinity, Infinity); |
46 testRound(-Infinity, -Infinity); | 56 testRound(-Infinity, -Infinity); |
47 testRound(NaN, NaN); | 57 testRound(NaN, NaN); |
48 | 58 |
49 // Regression test for a bug where a negative zero coming from Math.round | 59 // Regression test for a bug where a negative zero coming from Math.round |
50 // was not properly handled by other operations. | 60 // was not properly handled by other operations. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 testRound(-0, -0.49999999999999994); | 182 testRound(-0, -0.49999999999999994); |
173 testRound(-0, -0.5); | 183 testRound(-0, -0.5); |
174 testRound(-Math.pow(2,52)+1, -max_fraction); | 184 testRound(-Math.pow(2,52)+1, -max_fraction); |
175 testRound(-min_nonfraction, -min_nonfraction); | 185 testRound(-min_nonfraction, -min_nonfraction); |
176 testRound(-max_non_infinite, -max_non_infinite); | 186 testRound(-max_non_infinite, -max_non_infinite); |
177 | 187 |
178 testRound(min_smi31, min_smi31 - 0.5); | 188 testRound(min_smi31, min_smi31 - 0.5); |
179 testRound(min_smi31 + 1, min_smi31 + 0.5); | 189 testRound(min_smi31 + 1, min_smi31 + 0.5); |
180 testRound(min_smi32, min_smi32 - 0.5); | 190 testRound(min_smi32, min_smi32 - 0.5); |
181 testRound(min_smi32 + 1, min_smi32 + 0.5); | 191 testRound(min_smi32 + 1, min_smi32 + 0.5); |
OLD | NEW |