1--TEST--
2Test sprintf() function : usage variations - int 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() : integer formats with float values ***\n";
17
18// array of float type values
19
20$float_values = array (
21  2147483648,
22  0x800000001, // float value, beyond max positive int
23  020000000001, // float value, beyond max positive int
24  0.0,
25  -0.1,
26  1.0,
27  1e5,
28  -1e6,
29  1E8,
30  -1E9,
31  10.0000000000000000005,
32  10.5e+5
33);
34
35// various integer formats
36$int_formats = array(
37  "%d", "%hd", "%ld",
38  "%Ld", " %d", "%d ",
39  "\t%d", "\n%d", "%4d",
40  "%30d", "%[0-9]", "%*d"
41);
42
43$count = 1;
44foreach($float_values as $float_value) {
45  echo "\n-- Iteration $count --\n";
46
47  foreach($int_formats as $format) {
48    var_dump( sprintf($format, $float_value) );
49  }
50  $count++;
51};
52
53echo "Done";
54?>
55--EXPECT--
56*** Testing sprintf() : integer formats with float values ***
57
58-- Iteration 1 --
59string(11) "-2147483648"
60string(1) "d"
61string(11) "-2147483648"
62string(1) "d"
63string(12) " -2147483648"
64string(12) "-2147483648 "
65string(12) "	-2147483648"
66string(12) "
67-2147483648"
68string(11) "-2147483648"
69string(30) "                   -2147483648"
70string(4) "0-9]"
71string(1) "d"
72
73-- Iteration 2 --
74string(1) "1"
75string(1) "d"
76string(1) "1"
77string(1) "d"
78string(2) " 1"
79string(2) "1 "
80string(2) "	1"
81string(2) "
821"
83string(4) "   1"
84string(30) "                             1"
85string(4) "0-9]"
86string(1) "d"
87
88-- Iteration 3 --
89string(11) "-2147483647"
90string(1) "d"
91string(11) "-2147483647"
92string(1) "d"
93string(12) " -2147483647"
94string(12) "-2147483647 "
95string(12) "	-2147483647"
96string(12) "
97-2147483647"
98string(11) "-2147483647"
99string(30) "                   -2147483647"
100string(4) "0-9]"
101string(1) "d"
102
103-- Iteration 4 --
104string(1) "0"
105string(1) "d"
106string(1) "0"
107string(1) "d"
108string(2) " 0"
109string(2) "0 "
110string(2) "	0"
111string(2) "
1120"
113string(4) "   0"
114string(30) "                             0"
115string(4) "0-9]"
116string(1) "d"
117
118-- Iteration 5 --
119string(1) "0"
120string(1) "d"
121string(1) "0"
122string(1) "d"
123string(2) " 0"
124string(2) "0 "
125string(2) "	0"
126string(2) "
1270"
128string(4) "   0"
129string(30) "                             0"
130string(4) "0-9]"
131string(1) "d"
132
133-- Iteration 6 --
134string(1) "1"
135string(1) "d"
136string(1) "1"
137string(1) "d"
138string(2) " 1"
139string(2) "1 "
140string(2) "	1"
141string(2) "
1421"
143string(4) "   1"
144string(30) "                             1"
145string(4) "0-9]"
146string(1) "d"
147
148-- Iteration 7 --
149string(6) "100000"
150string(1) "d"
151string(6) "100000"
152string(1) "d"
153string(7) " 100000"
154string(7) "100000 "
155string(7) "	100000"
156string(7) "
157100000"
158string(6) "100000"
159string(30) "                        100000"
160string(4) "0-9]"
161string(1) "d"
162
163-- Iteration 8 --
164string(8) "-1000000"
165string(1) "d"
166string(8) "-1000000"
167string(1) "d"
168string(9) " -1000000"
169string(9) "-1000000 "
170string(9) "	-1000000"
171string(9) "
172-1000000"
173string(8) "-1000000"
174string(30) "                      -1000000"
175string(4) "0-9]"
176string(1) "d"
177
178-- Iteration 9 --
179string(9) "100000000"
180string(1) "d"
181string(9) "100000000"
182string(1) "d"
183string(10) " 100000000"
184string(10) "100000000 "
185string(10) "	100000000"
186string(10) "
187100000000"
188string(9) "100000000"
189string(30) "                     100000000"
190string(4) "0-9]"
191string(1) "d"
192
193-- Iteration 10 --
194string(11) "-1000000000"
195string(1) "d"
196string(11) "-1000000000"
197string(1) "d"
198string(12) " -1000000000"
199string(12) "-1000000000 "
200string(12) "	-1000000000"
201string(12) "
202-1000000000"
203string(11) "-1000000000"
204string(30) "                   -1000000000"
205string(4) "0-9]"
206string(1) "d"
207
208-- Iteration 11 --
209string(2) "10"
210string(1) "d"
211string(2) "10"
212string(1) "d"
213string(3) " 10"
214string(3) "10 "
215string(3) "	10"
216string(3) "
21710"
218string(4) "  10"
219string(30) "                            10"
220string(4) "0-9]"
221string(1) "d"
222
223-- Iteration 12 --
224string(7) "1050000"
225string(1) "d"
226string(7) "1050000"
227string(1) "d"
228string(8) " 1050000"
229string(8) "1050000 "
230string(8) "	1050000"
231string(8) "
2321050000"
233string(7) "1050000"
234string(30) "                       1050000"
235string(4) "0-9]"
236string(1) "d"
237Done
238