1--TEST--
2Test sprintf() function : usage variations - float formats with float 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 float values ***\n";
11
12// array of float type values
13
14$float_values = array (
15-2147483649, // float value
16  2147483648,  // float value
17  -0x80000001, // float value, beyond max negative int
18  0x800000001, // float value, beyond max positive int
19  020000000001, // float value, beyond max positive int
20  -020000000001, // float value, beyond max negative int
21  0.0,
22  -0.1,
23  10.0000000000000000005,
24  10.5e+5,
25  1e5,
26  -1e5,
27  1e-5,
28  -1e-5,
29  1e+5,
30  -1e+5,
31  1E5,
32  -1E5,
33  1E+5,
34  -1E+5,
35  1E-5,
36  -1E-5,
37  .5e+7,
38  -.5e+7,
39  .6e-19,
40  -.6e-19,
41  .05E+44,
42  -.05E+44,
43  .0034E-30,
44  -.0034E-30
45);
46
47// various float formats
48$float_formats = array(
49  "%f", "%hf", "%lf",
50  "%Lf", " %f", "%f ",
51  "\t%f", "\n%f", "%4f",
52  "%30f", "%[0-9]", "%*f",
53);
54
55$count = 1;
56foreach($float_values as $float_value) {
57  echo "\n-- Iteration $count --\n";
58
59  foreach($float_formats as $format) {
60    var_dump( sprintf($format, $float_value) );
61  }
62  $count++;
63};
64
65echo "Done";
66?>
67--EXPECT--
68*** Testing sprintf() : float formats with float values ***
69
70-- Iteration 1 --
71string(18) "-2147483649.000000"
72string(1) "f"
73string(18) "-2147483649.000000"
74string(1) "f"
75string(19) " -2147483649.000000"
76string(19) "-2147483649.000000 "
77string(19) "	-2147483649.000000"
78string(19) "
79-2147483649.000000"
80string(18) "-2147483649.000000"
81string(30) "            -2147483649.000000"
82string(4) "0-9]"
83string(1) "f"
84
85-- Iteration 2 --
86string(17) "2147483648.000000"
87string(1) "f"
88string(17) "2147483648.000000"
89string(1) "f"
90string(18) " 2147483648.000000"
91string(18) "2147483648.000000 "
92string(18) "	2147483648.000000"
93string(18) "
942147483648.000000"
95string(17) "2147483648.000000"
96string(30) "             2147483648.000000"
97string(4) "0-9]"
98string(1) "f"
99
100-- Iteration 3 --
101string(18) "-2147483649.000000"
102string(1) "f"
103string(18) "-2147483649.000000"
104string(1) "f"
105string(19) " -2147483649.000000"
106string(19) "-2147483649.000000 "
107string(19) "	-2147483649.000000"
108string(19) "
109-2147483649.000000"
110string(18) "-2147483649.000000"
111string(30) "            -2147483649.000000"
112string(4) "0-9]"
113string(1) "f"
114
115-- Iteration 4 --
116string(18) "34359738369.000000"
117string(1) "f"
118string(18) "34359738369.000000"
119string(1) "f"
120string(19) " 34359738369.000000"
121string(19) "34359738369.000000 "
122string(19) "	34359738369.000000"
123string(19) "
12434359738369.000000"
125string(18) "34359738369.000000"
126string(30) "            34359738369.000000"
127string(4) "0-9]"
128string(1) "f"
129
130-- Iteration 5 --
131string(17) "2147483649.000000"
132string(1) "f"
133string(17) "2147483649.000000"
134string(1) "f"
135string(18) " 2147483649.000000"
136string(18) "2147483649.000000 "
137string(18) "	2147483649.000000"
138string(18) "
1392147483649.000000"
140string(17) "2147483649.000000"
141string(30) "             2147483649.000000"
142string(4) "0-9]"
143string(1) "f"
144
145-- Iteration 6 --
146string(18) "-2147483649.000000"
147string(1) "f"
148string(18) "-2147483649.000000"
149string(1) "f"
150string(19) " -2147483649.000000"
151string(19) "-2147483649.000000 "
152string(19) "	-2147483649.000000"
153string(19) "
154-2147483649.000000"
155string(18) "-2147483649.000000"
156string(30) "            -2147483649.000000"
157string(4) "0-9]"
158string(1) "f"
159
160-- Iteration 7 --
161string(8) "0.000000"
162string(1) "f"
163string(8) "0.000000"
164string(1) "f"
165string(9) " 0.000000"
166string(9) "0.000000 "
167string(9) "	0.000000"
168string(9) "
1690.000000"
170string(8) "0.000000"
171string(30) "                      0.000000"
172string(4) "0-9]"
173string(1) "f"
174
175-- Iteration 8 --
176string(9) "-0.100000"
177string(1) "f"
178string(9) "-0.100000"
179string(1) "f"
180string(10) " -0.100000"
181string(10) "-0.100000 "
182string(10) "	-0.100000"
183string(10) "
184-0.100000"
185string(9) "-0.100000"
186string(30) "                     -0.100000"
187string(4) "0-9]"
188string(1) "f"
189
190-- Iteration 9 --
191string(9) "10.000000"
192string(1) "f"
193string(9) "10.000000"
194string(1) "f"
195string(10) " 10.000000"
196string(10) "10.000000 "
197string(10) "	10.000000"
198string(10) "
19910.000000"
200string(9) "10.000000"
201string(30) "                     10.000000"
202string(4) "0-9]"
203string(1) "f"
204
205-- Iteration 10 --
206string(14) "1050000.000000"
207string(1) "f"
208string(14) "1050000.000000"
209string(1) "f"
210string(15) " 1050000.000000"
211string(15) "1050000.000000 "
212string(15) "	1050000.000000"
213string(15) "
2141050000.000000"
215string(14) "1050000.000000"
216string(30) "                1050000.000000"
217string(4) "0-9]"
218string(1) "f"
219
220-- Iteration 11 --
221string(13) "100000.000000"
222string(1) "f"
223string(13) "100000.000000"
224string(1) "f"
225string(14) " 100000.000000"
226string(14) "100000.000000 "
227string(14) "	100000.000000"
228string(14) "
229100000.000000"
230string(13) "100000.000000"
231string(30) "                 100000.000000"
232string(4) "0-9]"
233string(1) "f"
234
235-- Iteration 12 --
236string(14) "-100000.000000"
237string(1) "f"
238string(14) "-100000.000000"
239string(1) "f"
240string(15) " -100000.000000"
241string(15) "-100000.000000 "
242string(15) "	-100000.000000"
243string(15) "
244-100000.000000"
245string(14) "-100000.000000"
246string(30) "                -100000.000000"
247string(4) "0-9]"
248string(1) "f"
249
250-- Iteration 13 --
251string(8) "0.000010"
252string(1) "f"
253string(8) "0.000010"
254string(1) "f"
255string(9) " 0.000010"
256string(9) "0.000010 "
257string(9) "	0.000010"
258string(9) "
2590.000010"
260string(8) "0.000010"
261string(30) "                      0.000010"
262string(4) "0-9]"
263string(1) "f"
264
265-- Iteration 14 --
266string(9) "-0.000010"
267string(1) "f"
268string(9) "-0.000010"
269string(1) "f"
270string(10) " -0.000010"
271string(10) "-0.000010 "
272string(10) "	-0.000010"
273string(10) "
274-0.000010"
275string(9) "-0.000010"
276string(30) "                     -0.000010"
277string(4) "0-9]"
278string(1) "f"
279
280-- Iteration 15 --
281string(13) "100000.000000"
282string(1) "f"
283string(13) "100000.000000"
284string(1) "f"
285string(14) " 100000.000000"
286string(14) "100000.000000 "
287string(14) "	100000.000000"
288string(14) "
289100000.000000"
290string(13) "100000.000000"
291string(30) "                 100000.000000"
292string(4) "0-9]"
293string(1) "f"
294
295-- Iteration 16 --
296string(14) "-100000.000000"
297string(1) "f"
298string(14) "-100000.000000"
299string(1) "f"
300string(15) " -100000.000000"
301string(15) "-100000.000000 "
302string(15) "	-100000.000000"
303string(15) "
304-100000.000000"
305string(14) "-100000.000000"
306string(30) "                -100000.000000"
307string(4) "0-9]"
308string(1) "f"
309
310-- Iteration 17 --
311string(13) "100000.000000"
312string(1) "f"
313string(13) "100000.000000"
314string(1) "f"
315string(14) " 100000.000000"
316string(14) "100000.000000 "
317string(14) "	100000.000000"
318string(14) "
319100000.000000"
320string(13) "100000.000000"
321string(30) "                 100000.000000"
322string(4) "0-9]"
323string(1) "f"
324
325-- Iteration 18 --
326string(14) "-100000.000000"
327string(1) "f"
328string(14) "-100000.000000"
329string(1) "f"
330string(15) " -100000.000000"
331string(15) "-100000.000000 "
332string(15) "	-100000.000000"
333string(15) "
334-100000.000000"
335string(14) "-100000.000000"
336string(30) "                -100000.000000"
337string(4) "0-9]"
338string(1) "f"
339
340-- Iteration 19 --
341string(13) "100000.000000"
342string(1) "f"
343string(13) "100000.000000"
344string(1) "f"
345string(14) " 100000.000000"
346string(14) "100000.000000 "
347string(14) "	100000.000000"
348string(14) "
349100000.000000"
350string(13) "100000.000000"
351string(30) "                 100000.000000"
352string(4) "0-9]"
353string(1) "f"
354
355-- Iteration 20 --
356string(14) "-100000.000000"
357string(1) "f"
358string(14) "-100000.000000"
359string(1) "f"
360string(15) " -100000.000000"
361string(15) "-100000.000000 "
362string(15) "	-100000.000000"
363string(15) "
364-100000.000000"
365string(14) "-100000.000000"
366string(30) "                -100000.000000"
367string(4) "0-9]"
368string(1) "f"
369
370-- Iteration 21 --
371string(8) "0.000010"
372string(1) "f"
373string(8) "0.000010"
374string(1) "f"
375string(9) " 0.000010"
376string(9) "0.000010 "
377string(9) "	0.000010"
378string(9) "
3790.000010"
380string(8) "0.000010"
381string(30) "                      0.000010"
382string(4) "0-9]"
383string(1) "f"
384
385-- Iteration 22 --
386string(9) "-0.000010"
387string(1) "f"
388string(9) "-0.000010"
389string(1) "f"
390string(10) " -0.000010"
391string(10) "-0.000010 "
392string(10) "	-0.000010"
393string(10) "
394-0.000010"
395string(9) "-0.000010"
396string(30) "                     -0.000010"
397string(4) "0-9]"
398string(1) "f"
399
400-- Iteration 23 --
401string(14) "5000000.000000"
402string(1) "f"
403string(14) "5000000.000000"
404string(1) "f"
405string(15) " 5000000.000000"
406string(15) "5000000.000000 "
407string(15) "	5000000.000000"
408string(15) "
4095000000.000000"
410string(14) "5000000.000000"
411string(30) "                5000000.000000"
412string(4) "0-9]"
413string(1) "f"
414
415-- Iteration 24 --
416string(15) "-5000000.000000"
417string(1) "f"
418string(15) "-5000000.000000"
419string(1) "f"
420string(16) " -5000000.000000"
421string(16) "-5000000.000000 "
422string(16) "	-5000000.000000"
423string(16) "
424-5000000.000000"
425string(15) "-5000000.000000"
426string(30) "               -5000000.000000"
427string(4) "0-9]"
428string(1) "f"
429
430-- Iteration 25 --
431string(8) "0.000000"
432string(1) "f"
433string(8) "0.000000"
434string(1) "f"
435string(9) " 0.000000"
436string(9) "0.000000 "
437string(9) "	0.000000"
438string(9) "
4390.000000"
440string(8) "0.000000"
441string(30) "                      0.000000"
442string(4) "0-9]"
443string(1) "f"
444
445-- Iteration 26 --
446string(9) "-0.000000"
447string(1) "f"
448string(9) "-0.000000"
449string(1) "f"
450string(10) " -0.000000"
451string(10) "-0.000000 "
452string(10) "	-0.000000"
453string(10) "
454-0.000000"
455string(9) "-0.000000"
456string(30) "                     -0.000000"
457string(4) "0-9]"
458string(1) "f"
459
460-- Iteration 27 --
461string(50) "5000000000000000069686058479707049565356032.000000"
462string(1) "f"
463string(50) "5000000000000000069686058479707049565356032.000000"
464string(1) "f"
465string(51) " 5000000000000000069686058479707049565356032.000000"
466string(51) "5000000000000000069686058479707049565356032.000000 "
467string(51) "	5000000000000000069686058479707049565356032.000000"
468string(51) "
4695000000000000000069686058479707049565356032.000000"
470string(50) "5000000000000000069686058479707049565356032.000000"
471string(50) "5000000000000000069686058479707049565356032.000000"
472string(4) "0-9]"
473string(1) "f"
474
475-- Iteration 28 --
476string(51) "-5000000000000000069686058479707049565356032.000000"
477string(1) "f"
478string(51) "-5000000000000000069686058479707049565356032.000000"
479string(1) "f"
480string(52) " -5000000000000000069686058479707049565356032.000000"
481string(52) "-5000000000000000069686058479707049565356032.000000 "
482string(52) "	-5000000000000000069686058479707049565356032.000000"
483string(52) "
484-5000000000000000069686058479707049565356032.000000"
485string(51) "-5000000000000000069686058479707049565356032.000000"
486string(51) "-5000000000000000069686058479707049565356032.000000"
487string(4) "0-9]"
488string(1) "f"
489
490-- Iteration 29 --
491string(8) "0.000000"
492string(1) "f"
493string(8) "0.000000"
494string(1) "f"
495string(9) " 0.000000"
496string(9) "0.000000 "
497string(9) "	0.000000"
498string(9) "
4990.000000"
500string(8) "0.000000"
501string(30) "                      0.000000"
502string(4) "0-9]"
503string(1) "f"
504
505-- Iteration 30 --
506string(9) "-0.000000"
507string(1) "f"
508string(9) "-0.000000"
509string(1) "f"
510string(10) " -0.000000"
511string(10) "-0.000000 "
512string(10) "	-0.000000"
513string(10) "
514-0.000000"
515string(9) "-0.000000"
516string(30) "                     -0.000000"
517string(4) "0-9]"
518string(1) "f"
519Done
520