1--TEST--
2Test sprintf() function : usage variations - scientific 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() : scientific formats with integer values ***\n";
11
12// array of integer 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// array of scientific formats
35$scientific_formats = array(
36  "%e", "%he", "%le",
37  "%Le", " %e", "%e ",
38  "\t%e", "\n%e", "%4e",
39  "%30e", "%[0-1]", "%*e"
40);
41
42$count = 1;
43foreach($integer_values as $integer_value) {
44  echo "\n-- Iteration $count --\n";
45
46  foreach($scientific_formats as $format) {
47    var_dump( sprintf($format, $integer_value) );
48  }
49  $count++;
50};
51
52echo "Done";
53?>
54--EXPECTF--
55*** Testing sprintf() : scientific formats with integer values ***
56
57-- Iteration 1 --
58string(11) "0.000000e+0"
59string(1) "e"
60string(11) "0.000000e+0"
61string(1) "e"
62string(12) " 0.000000e+0"
63string(12) "0.000000e+0 "
64string(12) "	0.000000e+0"
65string(12) "
660.000000e+0"
67string(11) "0.000000e+0"
68string(30) "                   0.000000e+0"
69string(4) "0-1]"
70string(1) "e"
71
72-- Iteration 2 --
73string(11) "1.000000e+0"
74string(1) "e"
75string(11) "1.000000e+0"
76string(1) "e"
77string(12) " 1.000000e+0"
78string(12) "1.000000e+0 "
79string(12) "	1.000000e+0"
80string(12) "
811.000000e+0"
82string(11) "1.000000e+0"
83string(30) "                   1.000000e+0"
84string(4) "0-1]"
85string(1) "e"
86
87-- Iteration 3 --
88string(12) "-1.000000e+0"
89string(1) "e"
90string(12) "-1.000000e+0"
91string(1) "e"
92string(13) " -1.000000e+0"
93string(13) "-1.000000e+0 "
94string(13) "	-1.000000e+0"
95string(13) "
96-1.000000e+0"
97string(12) "-1.000000e+0"
98string(30) "                  -1.000000e+0"
99string(4) "0-1]"
100string(1) "e"
101
102-- Iteration 4 --
103string(12) "-2.147484e+9"
104string(1) "e"
105string(12) "-2.147484e+9"
106string(1) "e"
107string(13) " -2.147484e+9"
108string(13) "-2.147484e+9 "
109string(13) "	-2.147484e+9"
110string(13) "
111-2.147484e+9"
112string(12) "-2.147484e+9"
113string(30) "                  -2.147484e+9"
114string(4) "0-1]"
115string(1) "e"
116
117-- Iteration 5 --
118string(12) "-2.147484e+9"
119string(1) "e"
120string(12) "-2.147484e+9"
121string(1) "e"
122string(13) " -2.147484e+9"
123string(13) "-2.147484e+9 "
124string(13) "	-2.147484e+9"
125string(13) "
126-2.147484e+9"
127string(12) "-2.147484e+9"
128string(30) "                  -2.147484e+9"
129string(4) "0-1]"
130string(1) "e"
131
132-- Iteration 6 --
133string(11) "2.147484e+9"
134string(1) "e"
135string(11) "2.147484e+9"
136string(1) "e"
137string(12) " 2.147484e+9"
138string(12) "2.147484e+9 "
139string(12) "	2.147484e+9"
140string(12) "
1412.147484e+9"
142string(11) "2.147484e+9"
143string(30) "                   2.147484e+9"
144string(4) "0-1]"
145string(1) "e"
146
147-- Iteration 7 --
148string(11) "2.147484e+9"
149string(1) "e"
150string(11) "2.147484e+9"
151string(1) "e"
152string(12) " 2.147484e+9"
153string(12) "2.147484e+9 "
154string(12) "	2.147484e+9"
155string(12) "
1562.147484e+9"
157string(11) "2.147484e+9"
158string(30) "                   2.147484e+9"
159string(4) "0-1]"
160string(1) "e"
161
162-- Iteration 8 --
163string(11) "4.667000e+3"
164string(1) "e"
165string(11) "4.667000e+3"
166string(1) "e"
167string(12) " 4.667000e+3"
168string(12) "4.667000e+3 "
169string(12) "	4.667000e+3"
170string(12) "
1714.667000e+3"
172string(11) "4.667000e+3"
173string(30) "                   4.667000e+3"
174string(4) "0-1]"
175string(1) "e"
176
177-- Iteration 9 --
178string(11) "4.779000e+3"
179string(1) "e"
180string(11) "4.779000e+3"
181string(1) "e"
182string(12) " 4.779000e+3"
183string(12) "4.779000e+3 "
184string(12) "	4.779000e+3"
185string(12) "
1864.779000e+3"
187string(11) "4.779000e+3"
188string(30) "                   4.779000e+3"
189string(4) "0-1]"
190string(1) "e"
191
192-- Iteration 10 --
193string(11) "4.095000e+3"
194string(1) "e"
195string(11) "4.095000e+3"
196string(1) "e"
197string(12) " 4.095000e+3"
198string(12) "4.095000e+3 "
199string(12) "	4.095000e+3"
200string(12) "
2014.095000e+3"
202string(11) "4.095000e+3"
203string(30) "                   4.095000e+3"
204string(4) "0-1]"
205string(1) "e"
206
207-- Iteration 11 --
208string(11) "2.500000e+2"
209string(1) "e"
210string(11) "2.500000e+2"
211string(1) "e"
212string(12) " 2.500000e+2"
213string(12) "2.500000e+2 "
214string(12) "	2.500000e+2"
215string(12) "
2162.500000e+2"
217string(11) "2.500000e+2"
218string(30) "                   2.500000e+2"
219string(4) "0-1]"
220string(1) "e"
221
222-- Iteration 12 --
223string(12) "-2.147484e+9"
224string(1) "e"
225string(12) "-2.147484e+9"
226string(1) "e"
227string(13) " -2.147484e+9"
228string(13) "-2.147484e+9 "
229string(13) "	-2.147484e+9"
230string(13) "
231-2.147484e+9"
232string(12) "-2.147484e+9"
233string(30) "                  -2.147484e+9"
234string(4) "0-1]"
235string(1) "e"
236
237-- Iteration 13 --
238string(11) "2.147484e+9"
239string(1) "e"
240string(11) "2.147484e+9"
241string(1) "e"
242string(12) " 2.147484e+9"
243string(12) "2.147484e+9 "
244string(12) "	2.147484e+9"
245string(12) "
2462.147484e+9"
247string(11) "2.147484e+9"
248string(30) "                   2.147484e+9"
249string(4) "0-1]"
250string(1) "e"
251
252-- Iteration 14 --
253string(11) "2.147484e+9"
254string(1) "e"
255string(11) "2.147484e+9"
256string(1) "e"
257string(12) " 2.147484e+9"
258string(12) "2.147484e+9 "
259string(12) "	2.147484e+9"
260string(12) "
2612.147484e+9"
262string(11) "2.147484e+9"
263string(30) "                   2.147484e+9"
264string(4) "0-1]"
265string(1) "e"
266
267-- Iteration 15 --
268string(11) "8.300000e+1"
269string(1) "e"
270string(11) "8.300000e+1"
271string(1) "e"
272string(12) " 8.300000e+1"
273string(12) "8.300000e+1 "
274string(12) "	8.300000e+1"
275string(12) "
2768.300000e+1"
277string(11) "8.300000e+1"
278string(30) "                   8.300000e+1"
279string(4) "0-1]"
280string(1) "e"
281
282-- Iteration 16 --
283string(11) "1.000000e+0"
284string(1) "e"
285string(11) "1.000000e+0"
286string(1) "e"
287string(12) " 1.000000e+0"
288string(12) "1.000000e+0 "
289string(12) "	1.000000e+0"
290string(12) "
2911.000000e+0"
292string(11) "1.000000e+0"
293string(30) "                   1.000000e+0"
294string(4) "0-1]"
295string(1) "e"
296
297-- Iteration 17 --
298string(12) "-2.147484e+9"
299string(1) "e"
300string(12) "-2.147484e+9"
301string(1) "e"
302string(13) " -2.147484e+9"
303string(13) "-2.147484e+9 "
304string(13) "	-2.147484e+9"
305string(13) "
306-2.147484e+9"
307string(12) "-2.147484e+9"
308string(30) "                  -2.147484e+9"
309string(4) "0-1]"
310string(1) "e"
311
312-- Iteration 18 --
313string(11) "2.147484e+9"
314string(1) "e"
315string(11) "2.147484e+9"
316string(1) "e"
317string(12) " 2.147484e+9"
318string(12) "2.147484e+9 "
319string(12) "	2.147484e+9"
320string(12) "
3212.147484e+9"
322string(11) "2.147484e+9"
323string(30) "                   2.147484e+9"
324string(4) "0-1]"
325string(1) "e"
326Done
327