| Index: test/mjsunit/math-round.js
|
| ===================================================================
|
| --- test/mjsunit/math-round.js (revision 8931)
|
| +++ test/mjsunit/math-round.js (working copy)
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2010 the V8 project authors. All rights reserved.
|
| +// Copyright 2011 the V8 project authors. All rights reserved.
|
| // Redistribution and use in source and binary forms, with or without
|
| // modification, are permitted provided that the following conditions are
|
| // met:
|
| @@ -27,10 +27,12 @@
|
|
|
| // Flags: --allow-natives-syntax
|
|
|
| +var test_id = 0;
|
| function testRound(expect, input) {
|
| - function doRound(input) {
|
| - return Math.round(input);
|
| - }
|
| + // Make source code different on each invocation to make
|
| + // sure it gets optimized each time.
|
| + var doRound = new Function('input',
|
| + '"' + (test_id++) + '";return Math.round(input)');
|
| assertEquals(expect, doRound(input));
|
| assertEquals(expect, doRound(input));
|
| assertEquals(expect, doRound(input));
|
| @@ -44,6 +46,21 @@
|
| testRound(-Infinity, -Infinity);
|
| testRound(NaN, NaN);
|
|
|
| +// Regression test for a bug where a negative zero coming from Math.round
|
| +// was not properly handled by other operations.
|
| +function roundsum(i, n) {
|
| + var ret = Math.round(n);
|
| + while (--i > 0) {
|
| + ret += Math.round(n);
|
| + }
|
| + return ret;
|
| +}
|
| +assertEquals(-0, roundsum(1, -0));
|
| +%OptimizeFunctionOnNextCall(roundsum);
|
| +// The optimized function will deopt. Run it with enough iterations to try
|
| +// to optimize via OSR (triggering the bug).
|
| +assertEquals(-0, roundsum(100000, -0));
|
| +
|
| testRound(1, 0.5);
|
| testRound(1, 0.7);
|
| testRound(1, 1);
|
|
|