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
|
--TEST--
Check for double NaN, Inf, -Inf, 0, and -0. IEEE 754 doubles
--FILE--
<?php
function str2bin($bytestring) {
$len = strlen($bytestring);
$output = '';
for ($i = 0; $i < $len; $i++) {
$bin = decbin(ord($bytestring[$i]));
$bin = str_pad($bin, 8, '0', STR_PAD_LEFT);
$output .= $bin;
}
return $output;
}
function test($type, $variable) {
$serialized = igbinary_serialize($variable);
$unserialized = igbinary_unserialize($serialized);
echo $type, ":\n";
var_dump($variable);
var_dump($unserialized);
echo " 6 5 4 3 2 1\n";
echo "3210987654321098765432109876543210987654321098765432109876543210\n";
echo str2bin(substr($serialized, 5, 8)), "\n";
echo "\n";
}
// exponent all-1, non zero mantissa
test('double NaN', NAN);
// sign 0, exp all-1, zero mantissa
test('double Inf', INF);
// sign 1, exp all-1, zero mantissa
test('double -Inf', -INF);
// sign 0, all-0
test('double 0.0', 0.0);
// sign 1, all-0
test('double -0.0', -1 * 0.0);
--EXPECTREGEX--
double NaN:
float\(NAN\)
float\(NAN\)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
.111111111110*1.*
double Inf:
float\(INF\)
float\(INF\)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
0111111111110000000000000000000000000000000000000000000000000000
double -Inf:
float\(-INF\)
float\(-INF\)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
1111111111110000000000000000000000000000000000000000000000000000
double 0.0:
float\(0\)
float\(0\)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
0000000000000000000000000000000000000000000000000000000000000000
double -0.0:
float\(-0\)
float\(-0\)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
1000000000000000000000000000000000000000000000000000000000000000
|