1--TEST--
2Default precision is sufficient to serialize all the information in floats
3--SKIPIF--
4<?php
5if (pack('s', 1) != "\x01\x00")
6    die("skip test for little-endian architectures");
7?>
8--FILE--
9<?php
10
11$numbers = array(
12    "0000000000000000", //0
13    "2d431cebe2362a3f", //.0002
14    "2e431cebe2362a3f", //.0002 + 10^-Accuracy[.0002]*1.01
15    "0000000000001000", //2^-1022. (minimum normal double)
16    "0100000000001000", //2^-1022. + 10^-Accuracy[2^-1022.]*1.01
17    "ffffffffffffef7f", //2^1024. (maximum normal double)
18    "feffffffffffef7f", //2^1024. - 10^-Accuracy[2^1024.]
19    "0100000000000000", //minimum subnormal double
20    "0200000000000000", //2nd minimum subnormal double
21    "fffffffffffff000", //maximum subnormal double
22    "fefffffffffff000", //2nd maximum subnormal double
23    "0000000000000f7f", //+inf
24    "0000000000000fff", //-inf
25);
26
27foreach ($numbers as $ns) {
28    $num = unpack("d", pack("H*", $ns)); $num = reset($num);
29    echo "number: ", sprintf("%.17e", $num), "... ";
30    $num2 = unserialize(serialize($num));
31    $repr = unpack("H*", pack("d", $num2)); $repr = reset($repr);
32    if ($repr == $ns)
33        echo "OK\n";
34    else
35        echo "mismatch\n\twas:    $ns\n\tbecame: $repr\n";
36}
37?>
38--EXPECT--
39number: 0.00000000000000000e+0... OK
40number: 2.00000000000000010e-4... OK
41number: 2.00000000000000037e-4... OK
42number: 2.22507385850720138e-308... OK
43number: 2.22507385850720188e-308... OK
44number: 1.79769313486231571e+308... OK
45number: 1.79769313486231551e+308... OK
46number: 4.94065645841246544e-324... OK
47number: 9.88131291682493088e-324... OK
48number: 3.87340857288933536e-304... OK
49number: 3.87340857288933455e-304... OK
50number: 1.06293653832877718e+304... OK
51number: -1.06293653832877718e+304... OK
52