forked from phadej/igbinary
-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathigbinary_044.phpt
More file actions
144 lines (120 loc) · 4.64 KB
/
Copy pathigbinary_044.phpt
File metadata and controls
144 lines (120 loc) · 4.64 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
--TEST--
Check for double extremes
--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, $validOutputs = null) {
$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";
$output = substr($serialized, 5, 8);
$binOutput = str2bin($output);
if ($validOutputs === null) {
echo $binOutput, "\n";
} else {
echo in_array($binOutput, $validOutputs) ? "ACCEPTABLE" : ("UNACCEPTABLE : " . $binOutput);
echo "\n";
}
echo "\n";
}
// subnormal number
test('double subnormal', -4.944584125e-314);
// max subnormal: sign 0, exponent 0, all 1 double
// http://www.exploringbinary.com/php-hangs-on-numeric-value-2-2250738585072011e-308/
test('double 1 max subnormal', 2.2250738585072010e-308);
test('double 2 max subnormal', 2.2250738585072011e-308);
$validOutputs = array('0000000000010000000000000000000000000000000000000000000000000000',
'0000000000001111111111111111111111111111111111111111111111111111');
test('double 3 max subnormal', 2.2250738585072012e-308, $validOutputs);
test('double 4 max subnormal', 2.2250738585072013e-308, $validOutputs);
test('double 5 max subnormal', 2.2250738585072014e-308);
// min subnormal number
test('double min subnormal', -4.9406564584124654e-324);
// big double
test('double big', -1.79769e308);
// max double, sign 0, exponent all-1 - 1, mantissa all-1
test('double max', 1.7976931348623157e308);
// small double
test('double small', -2.225e-308);
// min double, sign 1, exponent all-1 - 1, mantissa all-1
test('double min', -1.7976931348623157e308);
--EXPECTF--
double subnormal:
float(-4.944584125%S-314)
float(-4.944584125%S-314)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
1000000000000000000000000000001001010100100001010011000101110110
double 1 max subnormal:
float(2.2250738585072%SE-308)
float(2.2250738585072%SE-308)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
0000000000001111111111111111111111111111111111111111111111111111
double 2 max subnormal:
float(2.2250738585072%SE-308)
float(2.2250738585072%SE-308)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
0000000000001111111111111111111111111111111111111111111111111111
double 3 max subnormal:
float(2.2250738585072%SE-308)
float(2.2250738585072%SE-308)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
ACCEPTABLE
double 4 max subnormal:
float(2.2250738585072%SE-308)
float(2.2250738585072%SE-308)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
ACCEPTABLE
double 5 max subnormal:
float(2.2250738585072%SE-308)
float(2.2250738585072%SE-308)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
0000000000010000000000000000000000000000000000000000000000000000
double min subnormal:
float(-%SE-324)
float(-%SE-324)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
1000000000000000000000000000000000000000000000000000000000000001
double big:
float(-1.79769E+308)
float(-1.79769E+308)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
1111111111101111111111111111110001010111110010101000001010101110
double max:
float(1.7976931348623%SE+308)
float(1.7976931348623%SE+308)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
0111111111101111111111111111111111111111111111111111111111111111
double small:
float(-2.225E-308)
float(-2.225E-308)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
1000000000001111111111111101110100110001101000000000110001101101
double min:
float(-1.7976931348623%SE+308)
float(-1.7976931348623%SE+308)
6 5 4 3 2 1
3210987654321098765432109876543210987654321098765432109876543210
1111111111101111111111111111111111111111111111111111111111111111