Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Math/round/S15.8.2.15_A7.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 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
17 // CHECK#1
18 if (1 / Math.round(-0.5) !== 1 / -0) {
19 $ERROR("#1: '1 / Math.round(-0.5) !== 1 / -0'");
20 }
21
22 // CHECK#2
23 if (1 / Math.round(-0.25) !== 1 / -0) {
24 $ERROR("#2: '1 / Math.round(-0.25) !== 1 / -0'");
25 }
26
27 // CHECK#3
28 if (1 / Math.round(-0) !== 1 / -0) {
29 $ERROR("#3: '1 / Math.round(-0) !== 1 / -0'");
30 }
31
32 var x = 0;
33
34 // CHECK#4
35 x = 0.5 - Number.EPSILON / 4;
36 if (1 / Math.round(x) !== 1 / 0) {
37 $ERROR("#4: '1 / Math.round(" + x + ") !== 1 / 0'");
38 }
39
40 // CHECK#5
41 x = -(2 / Number.EPSILON - 1);
42 if (Math.round(x) !== x) {
43 $ERROR("#5: 'Math.round(" + x + ") !== " + x + "'");
44 }
45
46 // CHECK#6
47 x = -(1.5 / Number.EPSILON - 1);
48 if (Math.round(x) !== x) {
49 $ERROR("#6: 'Math.round(" + x + ") !== " + x + "'");
50 }
51
52 // CHECK#7
53 x = -(1 / Number.EPSILON + 1);
54 if (Math.round(x) !== x) {
55 $ERROR("#7: 'Math.round(" + x + ") !== " + x + "'");
56 }
57
58 // CHECK#8
59 x = 1 / Number.EPSILON + 1;
60 if (Math.round(x) !== x) {
61 $ERROR("#8: 'Math.round(" + x + ") !== " + x + "'");
62 }
63
64 // CHECK#9
65 x = 1.5 / Number.EPSILON - 1;
66 if (Math.round(x) !== x) {
67 $ERROR("#9: 'Math.round(" + x + ") !== " + x + "'");
68 }
69
70 // CHECK#10
71 x = 2 / Number.EPSILON - 1;
72 if (Math.round(x) !== x) {
73 $ERROR("#10: 'Math.round(" + x + ") !== " + x + "'");
74 }