Skip to content

Commit 24b62ff

Browse files
committed
Added tests for consistency with ceil() and floor() functions
1 parent 92ce3ae commit 24b62ff

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
--TEST--
2+
round() with different rounding modes
3+
--FILE--
4+
<?php
5+
$modes = [
6+
PHP_ROUND_CEILING, PHP_ROUND_FLOOR,
7+
];
8+
9+
$numbers = [
10+
2.5,
11+
-2.5,
12+
3.5,
13+
-3.5,
14+
7,
15+
-7,
16+
0.61,
17+
0.69,
18+
0,
19+
-0,
20+
1.9999,
21+
-1.9999,
22+
0.0001,
23+
-0.0001,
24+
];
25+
26+
echo "mode PHP_ROUND_CEILING\n";
27+
foreach($numbers as $number) {
28+
var_dump(ceil($number) === round($number, 0, PHP_ROUND_CEILING));
29+
}
30+
31+
echo "\n";
32+
echo "mode PHP_ROUND_FLOOR\n";
33+
foreach($numbers as $number) {
34+
var_dump(floor($number) === round($number, 0, PHP_ROUND_FLOOR));
35+
}
36+
37+
?>
38+
--EXPECT--
39+
mode PHP_ROUND_CEILING
40+
bool(true)
41+
bool(true)
42+
bool(true)
43+
bool(true)
44+
bool(true)
45+
bool(true)
46+
bool(true)
47+
bool(true)
48+
bool(true)
49+
bool(true)
50+
bool(true)
51+
bool(true)
52+
bool(true)
53+
bool(true)
54+
55+
mode PHP_ROUND_FLOOR
56+
bool(true)
57+
bool(true)
58+
bool(true)
59+
bool(true)
60+
bool(true)
61+
bool(true)
62+
bool(true)
63+
bool(true)
64+
bool(true)
65+
bool(true)
66+
bool(true)
67+
bool(true)
68+
bool(true)
69+
bool(true)

0 commit comments

Comments
 (0)