61ecc68e61b2c3f5a332ba992d4832a507479827
[framework/web/webkit-efl.git] / LayoutTests / fast / js / script-tests / math.js
1 description(
2
3 "This test checks the behavior of the Math object as described in 15.8 of the language specification."
4
5 );
6
7 shouldBe("Math.abs(NaN)", "NaN");
8 shouldBe("Math.abs(0)", "0");
9 shouldBe("Math.abs(-0)", "0");
10 shouldBe("Math.abs(1)", "1");
11 shouldBe("Math.abs(-1)", "1");
12 shouldBe("Math.abs(Number.MIN_VALUE)", "Number.MIN_VALUE");
13 shouldBe("Math.abs(-Number.MIN_VALUE)", "Number.MIN_VALUE");
14 shouldBe("Math.abs(Number.MAX_VALUE)", "Number.MAX_VALUE");
15 shouldBe("Math.abs(-Number.MAX_VALUE)", "Number.MAX_VALUE");
16 shouldBe("Math.abs(Infinity)", "Infinity");
17 shouldBe("Math.abs(-Infinity)", "Infinity");
18
19 shouldBe("Math.acos(NaN)", "NaN");
20 shouldBe("Math.acos(-0)", "Math.acos(0)");
21 shouldBe("Math.acos(1)", "0");
22 shouldBe("Math.acos(1.1)", "NaN");
23 shouldBe("Math.acos(-1.1)", "NaN");
24 shouldBe("Math.acos(Infinity)", "NaN");
25 shouldBe("Math.acos(-Infinity)", "NaN");
26
27 shouldBe("Math.asin(NaN)", "NaN");
28 shouldBe("Math.asin(0)", "0");
29 shouldBe("Math.asin(-0)", "-0");
30 shouldBe("Math.asin(1)", "-Math.asin(-1)");
31 shouldBe("Math.asin(1.1)", "NaN");
32 shouldBe("Math.asin(-1.1)", "NaN");
33 shouldBe("Math.asin(Infinity)", "NaN");
34 shouldBe("Math.asin(-Infinity)", "NaN");
35
36 shouldBe("Math.atan(NaN)", "NaN");
37 shouldBe("Math.atan(0)", "0");
38 shouldBe("Math.atan(-0)", "-0");
39 shouldBe("Math.atan(Infinity)", "-Math.atan(-Infinity)");
40
41 shouldBe("Math.atan2(NaN, NaN)", "NaN");
42 shouldBe("Math.atan2(NaN, 0)", "NaN");
43 shouldBe("Math.atan2(NaN, -0)", "NaN");
44 shouldBe("Math.atan2(NaN, 1)", "NaN");
45 shouldBe("Math.atan2(NaN, Infinity)", "NaN");
46 shouldBe("Math.atan2(NaN, -Infinity)", "NaN");
47 shouldBe("Math.atan2(0, NaN)", "NaN");
48 shouldBe("Math.atan2(-0, NaN)", "NaN");
49 shouldBe("Math.atan2(1, NaN)", "NaN");
50 shouldBe("Math.atan2(Infinity, NaN)", "NaN");
51 shouldBe("Math.atan2(-Infinity, NaN)", "NaN");
52
53 // Regression test for Bug 26978 (https://bugs.webkit.org/show_bug.cgi?id=26978)
54 var testStr = "";
55 var v = { valueOf: function() { testStr += "one"; return 1; } };
56 var w = { valueOf: function() { testStr += "two"; return 2; } };
57 Math.atan2(v, w);
58 shouldBe('testStr', '\"onetwo\"');
59
60 /*
61 • Ify>0andxis+0, theresult isanimplementation-dependent approximationto +π/2. 
62 • Ify>0andxis−0, theresult isanimplementation-dependent approximationto +π/2. 
63 • Ifyis+0andx>0, theresult is+0. 
64 • Ifyis+0andxis+0, theresult is+0. 
65 • Ifyis+0andxis−0, theresult isanimplementation-dependent approximationto +π. 
66 • Ifyis+0andx<0, theresult isanimplementation-dependent approximationto +π. 
67 • Ifyis−0andx>0, theresult is−0. 
68 • Ifyis−0andxis+0, theresult is−0. 
69 • Ifyis−0andxis−0, theresult isanimplementation-dependent approximationto −π. 
70 • Ifyis−0andx<0, theresult isanimplementation-dependent approximationto −π. 
71 • Ify<0andxis+0, theresult isanimplementation-dependent approximationto −π/2. 
72 • Ify<0andxis−0, theresult isanimplementation-dependent approximationto −π/2. 
73 • Ify>0andyisfiniteandxis+∞, theresult is+0. 
74 • Ify>0andyisfiniteandxis−∞, theresult ifanimplementation-dependent approximationto +π. 
75 • Ify<0andyisfiniteandxis+∞, theresult is−0. 
76 • Ify<0andyisfiniteandxis−∞, theresult isanimplementation-dependent approximationto−π. 
77 • Ifyis+∞andxisfinite, theresult isanimplementation-dependent approximationto +π/2. 
78 • Ifyis−∞andxisfinite, theresult isanimplementation-dependent approximationto −π/2. 
79 • Ifyis+∞andxis+∞, theresult isanimplementation-dependent approximationto +π/4. 
80 • Ifyis+∞andxis−∞, theresult isanimplementation-dependent approximationto +3π/4. 
81 • Ifyis−∞andxis+∞, theresult isanimplementation-dependent approximationto −π/4. 
82 • Ifyis−∞andxis−∞, theresult isanimplementation-dependent approximationto −3π/4.
83 */
84
85 shouldBe("Math.ceil(NaN)", "NaN");
86 shouldBe("Math.ceil(0)", "0");
87 shouldBe("Math.ceil(-0)", "-0");
88 shouldBe("Math.ceil(-0.5)", "-0");
89 shouldBe("Math.ceil(1)", "1");
90 shouldBe("Math.ceil(-1)", "-1");
91 shouldBe("Math.ceil(1.1)", "2");
92 shouldBe("Math.ceil(-1.1)", "-1");
93 shouldBe("Math.ceil(Number.MIN_VALUE)", "1");
94 shouldBe("Math.ceil(-Number.MIN_VALUE)", "-0");
95 shouldBe("Math.ceil(Number.MAX_VALUE)", "Number.MAX_VALUE");
96 shouldBe("Math.ceil(-Number.MAX_VALUE)", "-Number.MAX_VALUE");
97 shouldBe("Math.ceil(Infinity)", "Infinity");
98 shouldBe("Math.ceil(-Infinity)", "-Infinity");
99
100 shouldBe("Math.cos(NaN)", "NaN");
101 shouldBe("Math.cos(0)", "1");
102 shouldBe("Math.cos(-0)", "1");
103 shouldBe("Math.cos(Infinity)", "NaN");
104 shouldBe("Math.cos(-Infinity)", "NaN");
105
106 shouldBe("Math.exp(NaN)", "NaN");
107 shouldBe("Math.exp(0)", "1");
108 shouldBe("Math.exp(-0)", "1");
109 shouldBe("Math.exp(Infinity)", "Infinity");
110 shouldBe("Math.exp(-Infinity)", "0");
111
112 shouldBe("Math.floor(NaN)", "NaN");
113 shouldBe("Math.floor(0)", "0");
114 shouldBe("Math.floor(-0)", "-0");
115 shouldBe("Math.floor(0.5)", "0");
116 shouldBe("Math.floor(1)", "1");
117 shouldBe("Math.floor(-1)", "-1");
118 shouldBe("Math.floor(1.1)", "1");
119 shouldBe("Math.floor(-1.1)", "-2");
120 shouldBe("Math.floor(Number.MIN_VALUE)", "0");
121 shouldBe("Math.floor(-Number.MIN_VALUE)", "-1");
122 shouldBe("Math.floor(Number.MAX_VALUE)", "Number.MAX_VALUE");
123 shouldBe("Math.floor(-Number.MAX_VALUE)", "-Number.MAX_VALUE");
124 shouldBe("Math.floor(Infinity)", "Infinity");
125 shouldBe("Math.floor(-Infinity)", "-Infinity");
126
127 shouldBe("Math.log(NaN)", "NaN");
128 shouldBe("Math.log(0)", "-Infinity");
129 shouldBe("Math.log(-0)", "-Infinity");
130 shouldBe("Math.log(1)", "0");
131 shouldBe("Math.log(-1)", "NaN");
132 shouldBe("Math.log(-1.1)", "NaN");
133 shouldBe("Math.log(Infinity)", "Infinity");
134 shouldBe("Math.log(-Infinity)", "NaN");
135
136 shouldBe("Math.max()", "-Infinity");
137 shouldBe("Math.max(NaN)", "NaN");
138 shouldBe("Math.max(NaN,1)", "NaN");
139 shouldBe("Math.max(0)", "0");
140 shouldBe("Math.max(-0)", "-0");
141 shouldBe("Math.max(-0, 0)", "0");
142
143 shouldBe("Math.min()", "Infinity");
144 shouldBe("Math.min(NaN)", "NaN");
145 shouldBe("Math.min(NaN,1)", "NaN");
146 shouldBe("Math.min(0)", "0");
147 shouldBe("Math.min(-0)", "-0");
148 shouldBe("Math.min(-0, 0)", "-0");
149
150 shouldBe("Math.pow(NaN, NaN)", "NaN");
151 shouldBe("Math.pow(NaN, 0)", "1");
152 shouldBe("Math.pow(NaN, -0)", "1");
153 shouldBe("Math.pow(NaN, 1)", "NaN");
154 shouldBe("Math.pow(NaN, Infinity)", "NaN");
155 shouldBe("Math.pow(NaN, -Infinity)", "NaN");
156 shouldBe("Math.pow(0, NaN)", "NaN");
157 shouldBe("Math.pow(-0, NaN)", "NaN");
158 shouldBe("Math.pow(1, NaN)", "NaN");
159 shouldBe("Math.pow(Infinity, NaN)", "NaN");
160 shouldBe("Math.pow(-Infinity, NaN)", "NaN");
161
162 /*
163 • Ifabs(x)>1andyis+∞, theresult is+∞. 
164 • Ifabs(x)>1andyis−∞, theresult is+0. 
165 • Ifabs(x)==1andyis+∞, theresult isNaN. 
166 • Ifabs(x)==1andyis−∞, theresult isNaN. 
167 • Ifabs(x)<1andyis+∞, theresult is+0. 
168 • Ifabs(x)<1andyis−∞, theresult is+∞. 
169 • Ifxis+∞andy>0, theresult is+∞. 
170 • Ifxis+∞andy<0, theresult is+0. 
171 • Ifxis−∞andy>0andyisanoddinteger, theresult is−∞. 
172 • Ifxis−∞andy>0andyisnot anoddinteger, theresult is+∞. 
173 • Ifxis−∞andy<0andyisanoddinteger, theresult is−0. 
174 • Ifxis−∞andy<0andyisnot anoddinteger, theresult is+0. 
175 • Ifxis+0andy>0, theresult is+0. 
176 • Ifxis+0andy<0, theresult is+∞. 
177 • Ifxis−0andy>0andyisanoddinteger, theresult is−0. 
178 • Ifxis−0andy>0andyisnot anoddinteger, theresult is+0. 
179 • Ifxis−0andy<0andyisanoddinteger, theresult is−∞. 
180 • Ifxis−0andy<0andyisnot anoddinteger, theresult is+∞. 
181 • Ifx<0andxisfiniteandyisfiniteandyisnot aninteger, theresult isNaN.
182 */
183
184 shouldBe("Math.round(NaN)", "NaN");
185 shouldBe("Math.round(0)", "0");
186 shouldBe("Math.round(-0)", "-0");
187 shouldBe("Math.round(0.4)", "0");
188 shouldBe("Math.round(-0.4)", "-0");
189 shouldBe("Math.round(0.5)", "1");
190 shouldBe("Math.round(-0.5)", "-0");
191 shouldBe("Math.round(0.6)", "1");
192 shouldBe("Math.round(-0.6)", "-1");
193 shouldBe("Math.round(1)", "1");
194 shouldBe("Math.round(-1)", "-1");
195 shouldBe("Math.round(1.1)", "1");
196 shouldBe("Math.round(-1.1)", "-1");
197 shouldBe("Math.round(1.5)", "2");
198 shouldBe("Math.round(-1.5)", "-1");
199 shouldBe("Math.round(1.6)", "2");
200 shouldBe("Math.round(-1.6)", "-2");
201 shouldBe("Math.round(8640000000000000)", "8640000000000000");
202 // The following is expected. Double can't represent .5 in this case.
203 shouldBe("Math.round(8640000000000000.5)", "8640000000000000");
204 shouldBe("Math.round(8640000000000001)", "8640000000000001");
205 shouldBe("Math.round(8640000000000002)", "8640000000000002");
206 shouldBe("Math.round(9007199254740990)", "9007199254740990");
207 shouldBe("Math.round(9007199254740991)", "9007199254740991");
208 shouldBe("Math.round(1.7976931348623157e+308)", "1.7976931348623157e+308");
209 shouldBe("Math.round(-8640000000000000)", "-8640000000000000");
210 shouldBe("Math.round(-8640000000000001)", "-8640000000000001");
211 shouldBe("Math.round(-8640000000000002)", "-8640000000000002");
212 shouldBe("Math.round(-9007199254740990)", "-9007199254740990");
213 shouldBe("Math.round(-9007199254740991)", "-9007199254740991");
214 shouldBe("Math.round(-1.7976931348623157e+308)", "-1.7976931348623157e+308");
215 shouldBe("Math.round(Infinity)", "Infinity");
216 shouldBe("Math.round(-Infinity)", "-Infinity");
217
218 shouldBe("Math.sin(NaN)", "NaN");
219 shouldBe("Math.sin(0)", "0");
220 shouldBe("Math.sin(-0)", "-0");
221 shouldBe("Math.sin(Infinity)", "NaN");
222 shouldBe("Math.sin(-Infinity)", "NaN");
223
224 shouldBe("Math.sqrt(NaN)", "NaN");
225 shouldBe("Math.sqrt(0)", "0");
226 shouldBe("Math.sqrt(-0)", "-0");
227 shouldBe("Math.sqrt(1)", "1");
228 shouldBe("Math.sqrt(-1)", "NaN");
229 shouldBe("Math.sqrt(Infinity)", "Infinity");
230 shouldBe("Math.sqrt(-Infinity)", "NaN");
231
232 shouldBe("Math.tan(NaN)", "NaN");
233 shouldBe("Math.tan(0)", "0");
234 shouldBe("Math.tan(-0)", "-0");
235 shouldBe("Math.tan(Infinity)", "NaN");
236 shouldBe("Math.tan(-Infinity)", "NaN");
237
238 successfullyParsed = true;