1--TEST--
2Test sprintf() function : usage variations - float formats with integer values
3--FILE--
4<?php
5/* Prototype  : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
6 * Description: Return a formatted string
7 * Source code: ext/standard/formatted_print.c
8*/
9
10echo "*** Testing sprintf() : float formats with integer values ***\n";
11
12// array of int type values
13$integer_values = array (
14  0,
15  1,
16  -1,
17  -2147483648, // max negative integer value
18  -2147483647,
19  2147483647,  // max positive integer value
20  2147483640,
21  0x123B,      // integer as hexadecimal
22  0x12ab,
23  0Xfff,
24  0XFA,
25  -0x80000000, // max negative integer as hexadecimal
26  0x7fffffff,  // max positive integer as hexadecimal
27  0x7FFFFFFF,  // max positive integer as hexadecimal
28  0123,        // integer as octal
29  01,       // should be quivalent to octal 1
30  -020000000000, // max negative integer as octal
31  017777777777  // max positive integer as octal
32);
33
34// various float formats
35$float_formats = array(
36  "%f", "%hf", "%lf",
37  "%Lf", " %f", "%f ",
38  "\t%f", "\n%f", "%4f",
39  "%30f", "%[0-9]", "%*f"
40);
41
42$count = 1;
43foreach($integer_values as $int_value) {
44  echo "\n-- Iteration $count --\n";
45
46  foreach($float_formats as $format) {
47    // with two arguments
48    var_dump( sprintf($format, $int_value) );
49  }
50  $count++;
51};
52
53echo "Done";
54?>
55--EXPECTF--
56*** Testing sprintf() : float formats with integer values ***
57
58-- Iteration 1 --
59string(8) "0.000000"
60string(1) "f"
61string(8) "0.000000"
62string(1) "f"
63string(9) " 0.000000"
64string(9) "0.000000 "
65string(9) "	0.000000"
66string(9) "
670.000000"
68string(8) "0.000000"
69string(30) "                      0.000000"
70string(4) "0-9]"
71string(1) "f"
72
73-- Iteration 2 --
74string(8) "1.000000"
75string(1) "f"
76string(8) "1.000000"
77string(1) "f"
78string(9) " 1.000000"
79string(9) "1.000000 "
80string(9) "	1.000000"
81string(9) "
821.000000"
83string(8) "1.000000"
84string(30) "                      1.000000"
85string(4) "0-9]"
86string(1) "f"
87
88-- Iteration 3 --
89string(9) "-1.000000"
90string(1) "f"
91string(9) "-1.000000"
92string(1) "f"
93string(10) " -1.000000"
94string(10) "-1.000000 "
95string(10) "	-1.000000"
96string(10) "
97-1.000000"
98string(9) "-1.000000"
99string(30) "                     -1.000000"
100string(4) "0-9]"
101string(1) "f"
102
103-- Iteration 4 --
104string(18) "-2147483648.000000"
105string(1) "f"
106string(18) "-2147483648.000000"
107string(1) "f"
108string(19) " -2147483648.000000"
109string(19) "-2147483648.000000 "
110string(19) "	-2147483648.000000"
111string(19) "
112-2147483648.000000"
113string(18) "-2147483648.000000"
114string(30) "            -2147483648.000000"
115string(4) "0-9]"
116string(1) "f"
117
118-- Iteration 5 --
119string(18) "-2147483647.000000"
120string(1) "f"
121string(18) "-2147483647.000000"
122string(1) "f"
123string(19) " -2147483647.000000"
124string(19) "-2147483647.000000 "
125string(19) "	-2147483647.000000"
126string(19) "
127-2147483647.000000"
128string(18) "-2147483647.000000"
129string(30) "            -2147483647.000000"
130string(4) "0-9]"
131string(1) "f"
132
133-- Iteration 6 --
134string(17) "2147483647.000000"
135string(1) "f"
136string(17) "2147483647.000000"
137string(1) "f"
138string(18) " 2147483647.000000"
139string(18) "2147483647.000000 "
140string(18) "	2147483647.000000"
141string(18) "
1422147483647.000000"
143string(17) "2147483647.000000"
144string(30) "             2147483647.000000"
145string(4) "0-9]"
146string(1) "f"
147
148-- Iteration 7 --
149string(17) "2147483640.000000"
150string(1) "f"
151string(17) "2147483640.000000"
152string(1) "f"
153string(18) " 2147483640.000000"
154string(18) "2147483640.000000 "
155string(18) "	2147483640.000000"
156string(18) "
1572147483640.000000"
158string(17) "2147483640.000000"
159string(30) "             2147483640.000000"
160string(4) "0-9]"
161string(1) "f"
162
163-- Iteration 8 --
164string(11) "4667.000000"
165string(1) "f"
166string(11) "4667.000000"
167string(1) "f"
168string(12) " 4667.000000"
169string(12) "4667.000000 "
170string(12) "	4667.000000"
171string(12) "
1724667.000000"
173string(11) "4667.000000"
174string(30) "                   4667.000000"
175string(4) "0-9]"
176string(1) "f"
177
178-- Iteration 9 --
179string(11) "4779.000000"
180string(1) "f"
181string(11) "4779.000000"
182string(1) "f"
183string(12) " 4779.000000"
184string(12) "4779.000000 "
185string(12) "	4779.000000"
186string(12) "
1874779.000000"
188string(11) "4779.000000"
189string(30) "                   4779.000000"
190string(4) "0-9]"
191string(1) "f"
192
193-- Iteration 10 --
194string(11) "4095.000000"
195string(1) "f"
196string(11) "4095.000000"
197string(1) "f"
198string(12) " 4095.000000"
199string(12) "4095.000000 "
200string(12) "	4095.000000"
201string(12) "
2024095.000000"
203string(11) "4095.000000"
204string(30) "                   4095.000000"
205string(4) "0-9]"
206string(1) "f"
207
208-- Iteration 11 --
209string(10) "250.000000"
210string(1) "f"
211string(10) "250.000000"
212string(1) "f"
213string(11) " 250.000000"
214string(11) "250.000000 "
215string(11) "	250.000000"
216string(11) "
217250.000000"
218string(10) "250.000000"
219string(30) "                    250.000000"
220string(4) "0-9]"
221string(1) "f"
222
223-- Iteration 12 --
224string(18) "-2147483648.000000"
225string(1) "f"
226string(18) "-2147483648.000000"
227string(1) "f"
228string(19) " -2147483648.000000"
229string(19) "-2147483648.000000 "
230string(19) "	-2147483648.000000"
231string(19) "
232-2147483648.000000"
233string(18) "-2147483648.000000"
234string(30) "            -2147483648.000000"
235string(4) "0-9]"
236string(1) "f"
237
238-- Iteration 13 --
239string(17) "2147483647.000000"
240string(1) "f"
241string(17) "2147483647.000000"
242string(1) "f"
243string(18) " 2147483647.000000"
244string(18) "2147483647.000000 "
245string(18) "	2147483647.000000"
246string(18) "
2472147483647.000000"
248string(17) "2147483647.000000"
249string(30) "             2147483647.000000"
250string(4) "0-9]"
251string(1) "f"
252
253-- Iteration 14 --
254string(17) "2147483647.000000"
255string(1) "f"
256string(17) "2147483647.000000"
257string(1) "f"
258string(18) " 2147483647.000000"
259string(18) "2147483647.000000 "
260string(18) "	2147483647.000000"
261string(18) "
2622147483647.000000"
263string(17) "2147483647.000000"
264string(30) "             2147483647.000000"
265string(4) "0-9]"
266string(1) "f"
267
268-- Iteration 15 --
269string(9) "83.000000"
270string(1) "f"
271string(9) "83.000000"
272string(1) "f"
273string(10) " 83.000000"
274string(10) "83.000000 "
275string(10) "	83.000000"
276string(10) "
27783.000000"
278string(9) "83.000000"
279string(30) "                     83.000000"
280string(4) "0-9]"
281string(1) "f"
282
283-- Iteration 16 --
284string(8) "1.000000"
285string(1) "f"
286string(8) "1.000000"
287string(1) "f"
288string(9) " 1.000000"
289string(9) "1.000000 "
290string(9) "	1.000000"
291string(9) "
2921.000000"
293string(8) "1.000000"
294string(30) "                      1.000000"
295string(4) "0-9]"
296string(1) "f"
297
298-- Iteration 17 --
299string(18) "-2147483648.000000"
300string(1) "f"
301string(18) "-2147483648.000000"
302string(1) "f"
303string(19) " -2147483648.000000"
304string(19) "-2147483648.000000 "
305string(19) "	-2147483648.000000"
306string(19) "
307-2147483648.000000"
308string(18) "-2147483648.000000"
309string(30) "            -2147483648.000000"
310string(4) "0-9]"
311string(1) "f"
312
313-- Iteration 18 --
314string(17) "2147483647.000000"
315string(1) "f"
316string(17) "2147483647.000000"
317string(1) "f"
318string(18) " 2147483647.000000"
319string(18) "2147483647.000000 "
320string(18) "	2147483647.000000"
321string(18) "
3222147483647.000000"
323string(17) "2147483647.000000"
324string(30) "             2147483647.000000"
325string(4) "0-9]"
326string(1) "f"
327Done
328