|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 File Name: 15.8.2.15.js |
|
9 ECMA Section: 15.8.2.15 Math.round(x) |
|
10 Description: return the greatest number value that is closest to the |
|
11 argument and is an integer. if two integers are equally |
|
12 close to the argument. then the result is the number value |
|
13 that is closer to Infinity. if the argument is an integer, |
|
14 return the argument. |
|
15 special cases: |
|
16 - if x is NaN return NaN |
|
17 - if x = +0 return +0 |
|
18 - if x = -0 return -0 |
|
19 - if x = Infinity return Infinity |
|
20 - if x = -Infinity return -Infinity |
|
21 - if 0 < x < 0.5 return 0 |
|
22 - if -0.5 <= x < 0 return -0 |
|
23 example: |
|
24 Math.round( 3.5 ) == 4 |
|
25 Math.round( -3.5 ) == 3 |
|
26 also: |
|
27 - Math.round(x) == Math.floor( x + 0.5 ) |
|
28 except if x = -0. in that case, Math.round(x) = -0 |
|
29 |
|
30 and Math.floor( x+0.5 ) = +0 |
|
31 |
|
32 |
|
33 Author: christine@netscape.com |
|
34 Date: 7 july 1997 |
|
35 */ |
|
36 |
|
37 var SECTION = "15.8.2.15"; |
|
38 var VERSION = "ECMA_1"; |
|
39 var TITLE = "Math.round(x)"; |
|
40 var BUGNUMBER="331411"; |
|
41 |
|
42 var EXCLUDE = "true"; |
|
43 |
|
44 startTest(); |
|
45 |
|
46 writeHeaderToLog( SECTION + " "+ TITLE); |
|
47 |
|
48 new TestCase( SECTION, |
|
49 "Math.round.length", |
|
50 1, |
|
51 Math.round.length ); |
|
52 |
|
53 new TestCase( SECTION, |
|
54 "Math.round()", |
|
55 Number.NaN, |
|
56 Math.round() ); |
|
57 |
|
58 new TestCase( SECTION, |
|
59 "Math.round(null)", |
|
60 0, |
|
61 Math.round(0) ); |
|
62 |
|
63 new TestCase( SECTION, |
|
64 "Math.round(void 0)", |
|
65 Number.NaN, |
|
66 Math.round(void 0) ); |
|
67 |
|
68 new TestCase( SECTION, |
|
69 "Math.round(true)", |
|
70 1, |
|
71 Math.round(true) ); |
|
72 |
|
73 new TestCase( SECTION, |
|
74 "Math.round(false)", |
|
75 0, |
|
76 Math.round(false) ); |
|
77 |
|
78 new TestCase( SECTION, |
|
79 "Math.round('.99999')", |
|
80 1, |
|
81 Math.round('.99999') ); |
|
82 |
|
83 new TestCase( SECTION, |
|
84 "Math.round('12345e-2')", |
|
85 123, |
|
86 Math.round('12345e-2') ); |
|
87 |
|
88 new TestCase( SECTION, |
|
89 "Math.round(NaN)", |
|
90 Number.NaN, |
|
91 Math.round(Number.NaN) ); |
|
92 |
|
93 new TestCase( SECTION, |
|
94 "Math.round(0)", |
|
95 0, |
|
96 Math.round(0) ); |
|
97 |
|
98 new TestCase( SECTION, |
|
99 "Math.round(-0)", |
|
100 -0, |
|
101 Math.round(-0)); |
|
102 |
|
103 new TestCase( SECTION, |
|
104 "Infinity/Math.round(-0)", |
|
105 -Infinity, |
|
106 Infinity/Math.round(-0) ); |
|
107 |
|
108 new TestCase( SECTION, |
|
109 "Math.round(Infinity)", |
|
110 Number.POSITIVE_INFINITY, |
|
111 Math.round(Number.POSITIVE_INFINITY)); |
|
112 |
|
113 new TestCase( SECTION, |
|
114 "Math.round(-Infinity)", |
|
115 Number.NEGATIVE_INFINITY, |
|
116 Math.round(Number.NEGATIVE_INFINITY)); |
|
117 |
|
118 new TestCase( SECTION, |
|
119 "Math.round(0.49)", |
|
120 0, |
|
121 Math.round(0.49)); |
|
122 |
|
123 new TestCase( SECTION, |
|
124 "Math.round(0.5)", |
|
125 1, |
|
126 Math.round(0.5)); |
|
127 |
|
128 new TestCase( SECTION, |
|
129 "Math.round(0.51)", |
|
130 1, |
|
131 Math.round(0.51)); |
|
132 |
|
133 new TestCase( SECTION, |
|
134 "Math.round(-0.49)", |
|
135 -0, |
|
136 Math.round(-0.49)); |
|
137 |
|
138 new TestCase( SECTION, |
|
139 "Math.round(-0.5)", |
|
140 -0, |
|
141 Math.round(-0.5)); |
|
142 |
|
143 new TestCase( SECTION, |
|
144 "Infinity/Math.round(-0.49)", |
|
145 -Infinity, |
|
146 Infinity/Math.round(-0.49)); |
|
147 |
|
148 new TestCase( SECTION, |
|
149 "Infinity/Math.round(-0.5)", |
|
150 -Infinity, |
|
151 Infinity/Math.round(-0.5)); |
|
152 |
|
153 new TestCase( SECTION, |
|
154 "Math.round(-0.51)", |
|
155 -1, |
|
156 Math.round(-0.51)); |
|
157 |
|
158 new TestCase( SECTION, |
|
159 "Math.round(3.5)", |
|
160 4, |
|
161 Math.round(3.5)); |
|
162 |
|
163 new TestCase( SECTION, |
|
164 "Math.round(-3.5)", |
|
165 -3, |
|
166 Math.round(-3)); |
|
167 |
|
168 test(); |