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