|
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 var BUGNUMBER = 329383; |
|
8 var summary = 'Math copysign issues'; |
|
9 var actual = ''; |
|
10 var expect = ''; |
|
11 |
|
12 printBugNumber(BUGNUMBER); |
|
13 printStatus (summary); |
|
14 |
|
15 var inputs = [ |
|
16 -Infinity, |
|
17 -10.01, |
|
18 -9.01, |
|
19 -8.01, |
|
20 -7.01, |
|
21 -6.01, |
|
22 -5.01, |
|
23 -4.01, |
|
24 -Math.PI, |
|
25 -3.01, |
|
26 -2.01, |
|
27 -1.01, |
|
28 -0.5, |
|
29 -0.49, |
|
30 -0.01, |
|
31 -0, |
|
32 0, |
|
33 +0, |
|
34 0.01, |
|
35 0.49, |
|
36 0.50, |
|
37 0, |
|
38 1.01, |
|
39 2.01, |
|
40 3.01, |
|
41 Math.PI, |
|
42 4.01, |
|
43 5.01, |
|
44 6.01, |
|
45 7.01, |
|
46 8.01, |
|
47 9.01, |
|
48 10.01, |
|
49 Infinity |
|
50 ]; |
|
51 |
|
52 var iinput; |
|
53 |
|
54 for (iinput = 0; iinput < inputs.length; iinput++) |
|
55 { |
|
56 var input = inputs[iinput]; |
|
57 reportCompare(Math.round(input), |
|
58 emulateRound(input), |
|
59 summary + ': Math.round(' + input + ')'); |
|
60 } |
|
61 |
|
62 reportCompare(isNaN(Math.round(NaN)), |
|
63 isNaN(emulateRound(NaN)), |
|
64 summary + ': Math.round(' + input + ')'); |
|
65 |
|
66 function emulateRound(x) |
|
67 { |
|
68 if (!isFinite(x) || x === 0) return x |
|
69 if (-0.5 <= x && x < 0) return -0 |
|
70 return Math.floor(x + 0.5) |
|
71 } |
|
72 |
|
73 var z; |
|
74 |
|
75 z = Math.min(-0, 0); |
|
76 |
|
77 reportCompare(-Math.PI, Math.atan2(z, z), summary + ': Math.atan2(-0, -0)'); |
|
78 reportCompare(-Infinity, 1/z, summary + ': 1/-0'); |
|
79 |
|
80 z = Math.max(-0, 0); |
|
81 |
|
82 reportCompare(0, Math.atan2(z, z), summary + ': Math.atan2(0, 0)'); |
|
83 reportCompare(Infinity, 1/z, summary + ': 1/0'); |