OLD | NEW |
1 // Copyright 2010 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 25 matching lines...) Expand all Loading... |
37 %OptimizeFunctionOnNextCall(doRound); | 37 %OptimizeFunctionOnNextCall(doRound); |
38 assertEquals(expect, doRound(input)); | 38 assertEquals(expect, doRound(input)); |
39 } | 39 } |
40 | 40 |
41 testRound(0, 0); | 41 testRound(0, 0); |
42 testRound(-0, -0); | 42 testRound(-0, -0); |
43 testRound(Infinity, Infinity); | 43 testRound(Infinity, Infinity); |
44 testRound(-Infinity, -Infinity); | 44 testRound(-Infinity, -Infinity); |
45 testRound(NaN, NaN); | 45 testRound(NaN, NaN); |
46 | 46 |
| 47 // Regression test for a bug where a negative zero coming from Math.round |
| 48 // was not properly handled by other operations. |
| 49 function roundsum(i, n) { |
| 50 var ret = Math.round(n); |
| 51 while (--i > 0) { |
| 52 ret += Math.round(n); |
| 53 } |
| 54 return ret; |
| 55 } |
| 56 assertEquals(-0, roundsum(1, -0)); |
| 57 %OptimizeFunctionOnNextCall(roundsum); |
| 58 // The optimized function will deopt. Run it with enough iterations to try |
| 59 // to optimize via OSR (triggering the bug). |
| 60 assertEquals(-0, roundsum(100000, -0)); |
| 61 |
47 testRound(1, 0.5); | 62 testRound(1, 0.5); |
48 testRound(1, 0.7); | 63 testRound(1, 0.7); |
49 testRound(1, 1); | 64 testRound(1, 1); |
50 testRound(1, 1.1); | 65 testRound(1, 1.1); |
51 testRound(1, 1.49999); | 66 testRound(1, 1.49999); |
52 testRound(-0, -0.5); | 67 testRound(-0, -0.5); |
53 testRound(-1, -0.5000000000000001); | 68 testRound(-1, -0.5000000000000001); |
54 testRound(-1, -0.7); | 69 testRound(-1, -0.7); |
55 testRound(-1, -1); | 70 testRound(-1, -1); |
56 testRound(-1, -1.1); | 71 testRound(-1, -1.1); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 testRound(-Math.pow(2,52)+1, -max_fraction); | 163 testRound(-Math.pow(2,52)+1, -max_fraction); |
149 testRound(-min_nonfraction, -min_nonfraction); | 164 testRound(-min_nonfraction, -min_nonfraction); |
150 testRound(-max_non_infinite, -max_non_infinite); | 165 testRound(-max_non_infinite, -max_non_infinite); |
151 | 166 |
152 testRound(min_smi31, min_smi31 - 0.5); | 167 testRound(min_smi31, min_smi31 - 0.5); |
153 testRound(min_smi31 + 1, min_smi31 + 0.5); | 168 testRound(min_smi31 + 1, min_smi31 + 0.5); |
154 testRound(min_smi32, min_smi32 - 0.5); | 169 testRound(min_smi32, min_smi32 - 0.5); |
155 testRound(min_smi32 + 1, min_smi32 + 0.5); | 170 testRound(min_smi32 + 1, min_smi32 + 0.5); |
156 | 171 |
157 | 172 |
OLD | NEW |