Debian Codegraph @

js/src/tests/test262/built-ins/Math/round/S15.8.2.15_A6.js

raw
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 equal to 0 or greater than 0, or if x is less than -0.5,
7 Math.round(x) is equal to Math.floor(x+0.5)
8 es5id: 15.8.2.15_A6
9 description: >
10 Checking if Math.round(x) is equal to Math.floor(x+0.5), where x
11 equals to 0, greater than 0, or is less than -0.5; this check is
12 performed on 2000 argument x values
13 ---*/
14
15 // CHECK#1
16 for (var i = 0; i <= 1000; i++)
17 {
18 var x = i / 10.0;
19
20 assert.sameValue(
21 Math.round(x),
22 Math.floor(x + 0.5),
23 'Math.round(i / 10.0) must return the same value returned by Math.floor(x + 0.5)'
24 );
25 }
26
27 for (i = -5; i >= -1000; i--)
28 {
29 if (i === -5)
30 {
31 x = -0.500000000000001;
32 } else
33 {
34 x = i / 10.0;
35 }
36
37 assert.sameValue(
38 Math.round(x),
39 Math.floor(x + 0.5),
40 'Math.round(i / 10.0) must return the same value returned by Math.floor(x + 0.5)'
41 );
42 }
43
44 reportCompare(0, 0);