File: 041.phpt

package info (click to toggle)
php-msgpack 1%3A2.2.0~rc2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,200 kB
  • sloc: ansic: 3,817; xml: 416; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,080 bytes parent folder | download | duplicates (3)
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
--TEST--
Check for double NaN, Inf, -Inf, 0, and -0
--FILE--
<?php
function test($type, $variable, $check) {
    $serialized = msgpack_serialize($variable);
    $unserialized = msgpack_unserialize($serialized);

    echo $type, PHP_EOL;
    var_dump($variable);
    var_dump($unserialized);
    var_dump($check($unserialized));

    echo PHP_EOL;
}

test('double NaN:', NAN, "is_nan");
test('double Inf:', INF, "is_infinite");
test('double -Inf:', -INF, "is_infinite");
test('double 0.0:', 0.0, function($z) {
        $h = bin2hex(pack("E", $z));
        if ($h === "0000000000000000") {
            return true;
        }
        var_dump($h);
    }
);
test('double -0.0:', -0.0, function($z) {
        $h = bin2hex(pack("E", $z));
        if ($h === "8000000000000000") {
            return true;
        }
        var_dump($h);
    }
);

--EXPECTF--
double NaN:
float(NAN)
float(NAN)
bool(true)

double Inf:
float(INF)
float(INF)
bool(true)

double -Inf:
float(-INF)
float(-INF)
bool(true)

double 0.0:
float(0)
float(0)
bool(true)

double -0.0:
float(-0)
float(-0)
bool(true)