-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Expand file tree
/
Copy pathmin_max_array_fast_path.phpt
More file actions
107 lines (94 loc) · 1.85 KB
/
Copy pathmin_max_array_fast_path.phpt
File metadata and controls
107 lines (94 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--TEST--
min() and max() array long/double fast path preserves comparison behavior
--FILE--
<?php
$cases = [];
$cases["packed long"] = [4, 1, 7, -3, 2];
$long_sparse = [4, 1, 7];
unset($long_sparse[1]);
$long_sparse[5] = -2;
$cases["sparse long"] = $long_sparse;
$la = 4;
$lb = 9;
$cases["long refs"] = [&$la, &$lb, 3];
$cases["packed double"] = [4.5, 1.5, 7.5, -3.5, 2.5];
$dbl_sparse = [4.5, 1.5, 7.5];
unset($dbl_sparse[1]);
$dbl_sparse[5] = -2.5;
$cases["sparse double"] = $dbl_sparse;
$da = 4.5;
$db = 9.5;
$cases["double refs"] = [&$da, &$db, 3.5];
$cases["double equal"] = [2.5, 2.5, 2.5];
$cases["nan first"] = [NAN, 1.0, 2.0];
$cases["nan middle"] = [3.0, NAN, 1.0];
$cases["nan last"] = [3.0, 1.0, NAN];
$cases["inf"] = [INF, -INF, 0.0, 5.0];
$cases["single long"] = [7];
$cases["single double"] = [7.5];
$cases["first non-long"] = ["5", 3, 4];
$cases["fallback after longs"] = [5, 4, "3", 2];
$cases["fallback after doubles"] = [5.5, 4.5, "3", 2.5];
$cases["long then double"] = [5, 4, 2.5, 9];
$cases["double then long"] = [5.5, 4.5, 2, 9];
foreach ($cases as $name => $values) {
echo "-- $name --\n";
var_dump(min($values));
var_dump(max($values));
}
?>
--EXPECT--
-- packed long --
int(-3)
int(7)
-- sparse long --
int(-2)
int(7)
-- long refs --
int(3)
int(9)
-- packed double --
float(-3.5)
float(7.5)
-- sparse double --
float(-2.5)
float(7.5)
-- double refs --
float(3.5)
float(9.5)
-- double equal --
float(2.5)
float(2.5)
-- nan first --
float(1)
float(NAN)
-- nan middle --
float(1)
float(3)
-- nan last --
float(NAN)
float(3)
-- inf --
float(-INF)
float(INF)
-- single long --
int(7)
int(7)
-- single double --
float(7.5)
float(7.5)
-- first non-long --
int(3)
string(1) "5"
-- fallback after longs --
int(2)
int(5)
-- fallback after doubles --
float(2.5)
float(5.5)
-- long then double --
float(2.5)
int(9)
-- double then long --
int(2)
int(9)