Debian Codegraph @

js/src/jit-test/tests/basic/hypot-exact.js

raw
1 // Properties of Math.hypot that are guaranteed by the spec.
2
3 // If no arguments are passed, the result is +0.
4 assertEq(Math.hypot(), +0);
5
6 // If any argument is +∞, the result is +∞.
7 // If any argument is −∞, the result is +∞.
8 for (var inf of [Infinity, -Infinity]) {
9 assertEq(Math.hypot(inf, 0), Infinity);
10 assertEq(Math.hypot(0, inf), Infinity);
11 assertEq(Math.hypot(inf, inf), Infinity);
12 assertEq(Math.hypot(inf, -inf), Infinity);
13
14 assertEq(Math.hypot(inf, -0), Infinity);
15 assertEq(Math.hypot(-0, inf), Infinity);
16 assertEq(Math.hypot(inf, Math.MIN_VALUE), Infinity);
17 assertEq(Math.hypot(Math.MIN_VALUE, inf), Infinity);
18 assertEq(Math.hypot(inf, 1), Infinity);
19 assertEq(Math.hypot(1, inf), Infinity);
20
21 assertEq(Math.hypot(inf, 0, 0), Infinity);
22 assertEq(Math.hypot(0, inf, 0), Infinity);
23 assertEq(Math.hypot(0, 0, inf), Infinity);
24
25 assertEq(Math.hypot(inf, NaN), Infinity);
26 assertEq(Math.hypot(NaN, inf), Infinity);
27
28 assertEq(Math.hypot(inf, NaN, NaN), Infinity);
29 assertEq(Math.hypot(NaN, inf, NaN), Infinity);
30 assertEq(Math.hypot(NaN, NaN, inf), Infinity);
31
32 assertEq(Math.hypot(inf, NaN, NaN, NaN), Infinity);
33 assertEq(Math.hypot(NaN, inf, NaN, NaN), Infinity);
34 assertEq(Math.hypot(NaN, NaN, inf, NaN), Infinity);
35 assertEq(Math.hypot(NaN, NaN, NaN, inf), Infinity);
36 }
37
38 // If no argument is +∞ or −∞, and any argument is NaN, the result is NaN.
39 assertEq(Math.hypot(NaN), NaN);
40
41 assertEq(Math.hypot(NaN, 0), NaN);
42 assertEq(Math.hypot(0, NaN), NaN);
43
44 assertEq(Math.hypot(NaN, NaN), NaN);
45
46 assertEq(Math.hypot(NaN, 0, 0), NaN);
47 assertEq(Math.hypot(0, NaN, 0), NaN);
48 assertEq(Math.hypot(0, 0, NaN), NaN);
49
50 assertEq(Math.hypot(NaN, 0, 0, 0), NaN);
51 assertEq(Math.hypot(0, NaN, 0, 0), NaN);
52 assertEq(Math.hypot(0, 0, NaN, 0), NaN);
53 assertEq(Math.hypot(0, 0, 0, NaN), NaN);
54
55 assertEq(Math.hypot(Number.MAX_VALUE, Number.MIN_VALUE, NaN), NaN);
56 assertEq(Math.hypot(Number.MAX_VALUE, Number.MIN_VALUE, Number.MIN_VALUE, NaN), NaN);
57
58 // If all arguments are either +0 or -0, the result is +0.
59 assertEq(Math.hypot(-0, -0), +0);
60 assertEq(Math.hypot(+0, -0), +0);
61
62 assertEq(Math.hypot(-0, -0, -0), +0);
63 assertEq(Math.hypot(+0, -0, -0), +0);
64 assertEq(Math.hypot(-0, +0, -0), +0);
65 assertEq(Math.hypot(+0, +0, -0), +0);
66
67 assertEq(Math.hypot(-0, -0, -0, -0), +0);
68 assertEq(Math.hypot(+0, -0, -0, -0), +0);
69 assertEq(Math.hypot(-0, -0, +0, -0), +0);
70 assertEq(Math.hypot(+0, +0, +0, -0), +0);
71 assertEq(Math.hypot(-0, -0, -0, +0), +0);
72
73 // The length property of the hypot function is 2.
74 assertEq(Math.hypot.length, 2);