Skip to content

Commit 6775c24

Browse files
committed
fix #108
AFAICT NANs occupy a bit space of more than 1.787e19 possible values
1 parent baefefc commit 6775c24

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

tests/041.phpt

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,60 @@
22
Check for double NaN, Inf, -Inf, 0, and -0
33
--FILE--
44
<?php
5-
function test($type, $variable) {
5+
function test($type, $variable, $check) {
66
$serialized = msgpack_serialize($variable);
77
$unserialized = msgpack_unserialize($serialized);
88

99
echo $type, PHP_EOL;
1010
var_dump($variable);
1111
var_dump($unserialized);
12+
var_dump($check($unserialized));
1213

13-
echo bin2hex($serialized), PHP_EOL;
1414
echo PHP_EOL;
1515
}
1616

17-
test('double NaN:', NAN);
18-
test('double Inf:', INF);
19-
test('double -Inf:', -INF);
20-
test('double 0.0:', 0.0);
21-
test('double -0.0:', -0.0);
17+
test('double NaN:', NAN, "is_nan");
18+
test('double Inf:', INF, "is_infinite");
19+
test('double -Inf:', -INF, "is_infinite");
20+
test('double 0.0:', 0.0, function($z) {
21+
$h = bin2hex(pack("E", $z));
22+
if ($h === "0000000000000000") {
23+
return true;
24+
}
25+
var_dump($h);
26+
}
27+
);
28+
test('double -0.0:', -0.0, function($z) {
29+
$h = bin2hex(pack("E", $z));
30+
if ($h === "8000000000000000") {
31+
return true;
32+
}
33+
var_dump($h);
34+
}
35+
);
2236

2337
--EXPECTF--
2438
double NaN:
2539
float(NAN)
2640
float(NAN)
27-
cb7ff8000000000000
41+
bool(true)
2842

2943
double Inf:
3044
float(INF)
3145
float(INF)
32-
cb7ff0000000000000
46+
bool(true)
3347

3448
double -Inf:
3549
float(-INF)
3650
float(-INF)
37-
cbfff0000000000000
51+
bool(true)
3852

3953
double 0.0:
4054
float(0)
4155
float(0)
42-
cb0000000000000000
56+
bool(true)
4357

4458
double -0.0:
4559
float(-0)
4660
float(-0)
47-
cb8000000000000000
61+
bool(true)

0 commit comments

Comments
 (0)