| 1 |
// Copyright 2009 the Sputnik authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
info: | |
| 6 |
If x is less than or equal to -0 and x is greater than or equal to -0.5, |
| 7 |
Math.round(x) is equal to -0 |
| 8 |
es5id: 15.8.2.15_A7 |
| 9 |
description: > |
| 10 |
`Math.round(x)` differs from `Math.floor(x + 0.5)`: |
| 11 |
|
| 12 |
1) for values in [-0.5; -0] |
| 13 |
2) for 0.5 - Number.EPSILON / 4 |
| 14 |
3) for odd integers in [-(2 / Number.EPSILON - 1); -(1 / Number.EPSILON + 1)] or in [1 / Number.EPSILON + 1; 2 / Number.EPSILON - 1] |
| 15 |
---*/ |
| 16 |
assert.sameValue( |
| 17 |
1 / Math.round(-0.5), |
| 18 |
1 / -0, |
| 19 |
'The result of evaluating (1 / Math.round(-0.5)) is expected to be 1 / -0' |
| 20 |
); |
| 21 |
|
| 22 |
assert.sameValue( |
| 23 |
1 / Math.round(-0.25), |
| 24 |
1 / -0, |
| 25 |
'The result of evaluating (1 / Math.round(-0.25)) is expected to be 1 / -0' |
| 26 |
); |
| 27 |
|
| 28 |
assert.sameValue(1 / Math.round(-0), 1 / -0, 'The result of evaluating (1 / Math.round(-0)) is expected to be 1 / -0'); |
| 29 |
|
| 30 |
var x = 0; |
| 31 |
|
| 32 |
// CHECK#4 |
| 33 |
x = 0.5 - Number.EPSILON / 4; |
| 34 |
assert.sameValue(1 / Math.round(x), 1 / 0, 'The result of evaluating (1 / Math.round(x)) is expected to be 1 / 0'); |
| 35 |
|
| 36 |
// CHECK#5 |
| 37 |
x = -(2 / Number.EPSILON - 1); |
| 38 |
assert.sameValue(Math.round(x), x, 'Math.round(-(2 / Number.EPSILON - 1)) returns x'); |
| 39 |
|
| 40 |
// CHECK#6 |
| 41 |
x = -(1.5 / Number.EPSILON - 1); |
| 42 |
assert.sameValue(Math.round(x), x, 'Math.round(-(1.5 / Number.EPSILON - 1)) returns x'); |
| 43 |
|
| 44 |
// CHECK#7 |
| 45 |
x = -(1 / Number.EPSILON + 1); |
| 46 |
assert.sameValue(Math.round(x), x, 'Math.round(-(1 / Number.EPSILON + 1)) returns x'); |
| 47 |
|
| 48 |
// CHECK#8 |
| 49 |
x = 1 / Number.EPSILON + 1; |
| 50 |
assert.sameValue(Math.round(x), x, 'Math.round(1 / Number.EPSILON + 1) returns x'); |
| 51 |
|
| 52 |
// CHECK#9 |
| 53 |
x = 1.5 / Number.EPSILON - 1; |
| 54 |
assert.sameValue(Math.round(x), x, 'Math.round(1.5 / Number.EPSILON - 1) returns x'); |
| 55 |
|
| 56 |
// CHECK#10 |
| 57 |
x = 2 / Number.EPSILON - 1; |
| 58 |
assert.sameValue(Math.round(x), x, 'Math.round(2 / Number.EPSILON - 1) returns x'); |
| 59 |
|
| 60 |
reportCompare(0, 0); |