1--TEST--
2Test sprintf() function : usage variations - hexa formats with float values
3--SKIPIF--
4<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
5--FILE--
6<?php
7/* Prototype  : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
8 * Description: Return a formatted string
9 * Source code: ext/standard/formatted_print.c
10*/
11
12echo "*** Testing sprintf() : hexa formats with float values ***\n";
13
14// array of float values
15$float_values = array(
16  2147483647,
17  0x800000001, // float value, beyond max positive int
18  020000000001, // float value, beyond max positive int
19  0.0,
20  -0.1,
21  1.0,
22  1e5,
23  -1e6,
24  1E8,
25  -1E9,
26  10.0000000000000000005,
27  10.5e+5
28);
29
30// array of hexa formats
31$hexa_formats = array(
32  "%x", "%xx", "%lx",
33  "%Lx", " %x", "%x ",
34  "\t%x", "\n%x", "%4x",
35  "%30x", "%[0-9A-Fa-f]", "%*x"
36);
37
38$count = 1;
39foreach($float_values as $float_value) {
40  echo "\n-- Iteration $count --\n";
41
42  foreach($hexa_formats as $format) {
43    // with two arguments
44    var_dump( sprintf($format, $float_value) );
45  }
46  $count++;
47};
48
49echo "Done";
50?>
51--EXPECT--
52*** Testing sprintf() : hexa formats with float values ***
53
54-- Iteration 1 --
55string(8) "7fffffff"
56string(9) "7fffffffx"
57string(8) "7fffffff"
58string(1) "x"
59string(9) " 7fffffff"
60string(9) "7fffffff "
61string(9) "	7fffffff"
62string(9) "
637fffffff"
64string(8) "7fffffff"
65string(30) "                      7fffffff"
66string(10) "0-9A-Fa-f]"
67string(1) "x"
68
69-- Iteration 2 --
70string(9) "800000001"
71string(10) "800000001x"
72string(9) "800000001"
73string(1) "x"
74string(10) " 800000001"
75string(10) "800000001 "
76string(10) "	800000001"
77string(10) "
78800000001"
79string(9) "800000001"
80string(30) "                     800000001"
81string(10) "0-9A-Fa-f]"
82string(1) "x"
83
84-- Iteration 3 --
85string(8) "80000001"
86string(9) "80000001x"
87string(8) "80000001"
88string(1) "x"
89string(9) " 80000001"
90string(9) "80000001 "
91string(9) "	80000001"
92string(9) "
9380000001"
94string(8) "80000001"
95string(30) "                      80000001"
96string(10) "0-9A-Fa-f]"
97string(1) "x"
98
99-- Iteration 4 --
100string(1) "0"
101string(2) "0x"
102string(1) "0"
103string(1) "x"
104string(2) " 0"
105string(2) "0 "
106string(2) "	0"
107string(2) "
1080"
109string(4) "   0"
110string(30) "                             0"
111string(10) "0-9A-Fa-f]"
112string(1) "x"
113
114-- Iteration 5 --
115string(1) "0"
116string(2) "0x"
117string(1) "0"
118string(1) "x"
119string(2) " 0"
120string(2) "0 "
121string(2) "	0"
122string(2) "
1230"
124string(4) "   0"
125string(30) "                             0"
126string(10) "0-9A-Fa-f]"
127string(1) "x"
128
129-- Iteration 6 --
130string(1) "1"
131string(2) "1x"
132string(1) "1"
133string(1) "x"
134string(2) " 1"
135string(2) "1 "
136string(2) "	1"
137string(2) "
1381"
139string(4) "   1"
140string(30) "                             1"
141string(10) "0-9A-Fa-f]"
142string(1) "x"
143
144-- Iteration 7 --
145string(5) "186a0"
146string(6) "186a0x"
147string(5) "186a0"
148string(1) "x"
149string(6) " 186a0"
150string(6) "186a0 "
151string(6) "	186a0"
152string(6) "
153186a0"
154string(5) "186a0"
155string(30) "                         186a0"
156string(10) "0-9A-Fa-f]"
157string(1) "x"
158
159-- Iteration 8 --
160string(16) "fffffffffff0bdc0"
161string(17) "fffffffffff0bdc0x"
162string(16) "fffffffffff0bdc0"
163string(1) "x"
164string(17) " fffffffffff0bdc0"
165string(17) "fffffffffff0bdc0 "
166string(17) "	fffffffffff0bdc0"
167string(17) "
168fffffffffff0bdc0"
169string(16) "fffffffffff0bdc0"
170string(30) "              fffffffffff0bdc0"
171string(10) "0-9A-Fa-f]"
172string(1) "x"
173
174-- Iteration 9 --
175string(7) "5f5e100"
176string(8) "5f5e100x"
177string(7) "5f5e100"
178string(1) "x"
179string(8) " 5f5e100"
180string(8) "5f5e100 "
181string(8) "	5f5e100"
182string(8) "
1835f5e100"
184string(7) "5f5e100"
185string(30) "                       5f5e100"
186string(10) "0-9A-Fa-f]"
187string(1) "x"
188
189-- Iteration 10 --
190string(16) "ffffffffc4653600"
191string(17) "ffffffffc4653600x"
192string(16) "ffffffffc4653600"
193string(1) "x"
194string(17) " ffffffffc4653600"
195string(17) "ffffffffc4653600 "
196string(17) "	ffffffffc4653600"
197string(17) "
198ffffffffc4653600"
199string(16) "ffffffffc4653600"
200string(30) "              ffffffffc4653600"
201string(10) "0-9A-Fa-f]"
202string(1) "x"
203
204-- Iteration 11 --
205string(1) "a"
206string(2) "ax"
207string(1) "a"
208string(1) "x"
209string(2) " a"
210string(2) "a "
211string(2) "	a"
212string(2) "
213a"
214string(4) "   a"
215string(30) "                             a"
216string(10) "0-9A-Fa-f]"
217string(1) "x"
218
219-- Iteration 12 --
220string(6) "100590"
221string(7) "100590x"
222string(6) "100590"
223string(1) "x"
224string(7) " 100590"
225string(7) "100590 "
226string(7) "	100590"
227string(7) "
228100590"
229string(6) "100590"
230string(30) "                        100590"
231string(10) "0-9A-Fa-f]"
232string(1) "x"
233Done
234