Annotation of embedaddon/php/ext/standard/tests/strings/printf_64bit.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test printf() function (64bit)
3: --SKIPIF--
4: <?php
5: if (!(PHP_INT_MAX > 2147483647)) {
6: die("skip 64bit test only");
7: }
8: ?>
9: --INI--
10: precision=14
11: --FILE--
12: <?php
13:
14: /* Various input arrays for different format types */
15:
16: $float_variation = array( "%f", "%-f", "%+f", "%7.2f", "%-7.2f", "%07.2f", "%-07.2f", "%'#7.2f" );
17: $float_numbers = array( 0, 1, -1, 0.32, -0.32, 3.4. -3.4, 2.54, -2.54, 1.2345678e99, -1.2345678e99 );
18:
19: $int_variation = array( "%d", "%-d", "%+d", "%7.2d", "%-7.2d", "%07.2d", "%-07.2d", "%'#7.2d" );
20: $int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );
21:
22: $char_variation = array( 'a', "a", 67, -67, 99 );
23:
24: $string_variation = array( "%5s", "%-5s", "%05s", "%'#5s" );
25: $strings = array( NULL, "abc", 'aaa' );
26:
27: /* Checking warning messages */
28:
29: /* Zero argument */
30: echo "\n*** Output for zero argument ***\n";
31: printf();
32:
33: /* Number of arguments not matching as specified in format field */
34: echo "\n*** Output for insufficient number of arguments ***\n";
35: $string = "dingy%sflem%dwombat";
36: $nbr = 5;
37: $name = "voudras";
38: printf("%d $string %s", $nbr, $name);
39:
40:
41: /* Scalar argument */
42: echo "\n*** Output for scalar argument ***\n";
43: printf(3);
44:
45: /* NULL argument */
46: echo "\n*** Output for NULL as argument ***\n";
47: printf(NULL);
48:
49:
50: /* Float type variations */
51:
52: $counter = 1;
53: echo "\n\n*** Output for float type ***\n";
54: echo "\n Input Float numbers variation array is:\n";
55: print_r($float_numbers);
56:
57: foreach( $float_variation as $float_var )
58: {
59: echo "\n\nFloat Iteration $counter";
60: foreach( $float_numbers as $float_num )
61: {
62: echo "\n";
63: printf( $float_var, $float_num );
64: }
65: $counter++;
66: }
67:
68:
69: /* Integer type variations */
70:
71: $counter = 1;
72: echo "\n\n*** Output for integer type ***\n";
73: echo "\n Input Integer numbers variation array is:\n";
74: print_r($int_numbers);
75:
76: foreach( $int_variation as $int_var )
77: {
78: echo "\n\nInteger Iteration $counter";
79: foreach( $int_numbers as $int_num )
80: {
81: echo "\n";
82: printf( $int_var, $int_num );
83: }
84: $counter++;
85: }
86:
87:
88: /* Binary type variations */
89:
90: echo "\n\n*** Output for binary type ***\n";
91: echo "\n Input numbers variation array is:\n";
92: print_r($int_numbers);
93:
94: foreach( $int_numbers as $bin_num )
95: {
96: echo "\n";
97: printf( "%b", $bin_num );
98: }
99:
100:
101: /* Chararter type variations */
102: echo "\n\n*** Output for char type ***\n";
103: echo "\n Input Characters variation array is:\n";
104: print_r($char_variation);
105:
106: foreach( $char_variation as $char )
107: {
108: echo "\n";
109: printf( "%c", $char );
110: }
111:
112: /* Scientific type variations */
113: echo "\n\n*** Output for scientific type ***\n";
114: echo "\n Input numbers variation array is:\n";
115: print_r($int_numbers);
116:
117: foreach( $int_numbers as $num )
118: {
119: echo "\n";
120: printf( "%e", $num );
121: }
122:
123: /* Unsigned Integer type variation */
124: echo "\n\n*** Output for unsigned integer type ***\n";
125: echo "\n Input Integer numbers variation array is:\n";
126: print_r($int_numbers);
127:
128: foreach( $int_numbers as $unsig_num )
129: {
130: echo "\n";
131: printf( "%u", $unsig_num );
132: }
133:
134: /* Octal type variations */
135: echo "\n\n*** Output for octal type ***\n";
136: echo "\n Input numbers variation array is:\n";
137: print_r($int_numbers);
138:
139: foreach( $int_numbers as $octal_num )
140: {
141: echo "\n";
142: printf( "%o", $octal_num );
143: }
144:
145: /* Hexadecimal type variations */
146: echo "\n\n*** Output for hexadecimal type ***\n";
147: echo "\n Input numbers variation array is:\n";
148: print_r($int_numbers);
149:
150: foreach( $int_numbers as $hexa_num )
151: {
152: echo "\n";
153: printf( "%x", $hexa_num );
154: }
155:
156: /* String type variations */
157: echo "\n\n*** Output for string type ***\n";
158: echo "\n Input Strings format variation array is:\n";
159: print_r($string_variation);
160: echo "\n Input strings variation array is:\n";
161: print_r($strings);
162:
163: foreach( $string_variation as $string_var )
164: {
165: foreach( $strings as $str )
166: {
167: echo "\n";
168: printf( $string_var, $str );
169: }
170: }
171:
172:
173: /* variations of %g type */
174: $format_g = array("%g", "%.0g", "%+g", "%-g", "%-1.2g", "%+1.2g", "%G", "%.0G", "%+G", "%-G", "%-1.2G", "%+1.2G");
175:
176: echo "\n\n*** Output for '%g' type ***\n";
177: echo "\n Input format variation array is:\n";
178: print_r($format_g);
179:
180: foreach( $format_g as $formatg )
181: {
182: printf("\n$formatg",123456);
183: printf("\n$formatg",-123456);
184: }
185:
186:
187: /* Some more typical cases */
188:
189: $tempnum = 12345;
190: $tempstring = "abcdefghjklmnpqrstuvwxyz";
191:
192: echo"\n\n*** Output for '%%%.2f' as the format parameter ***\n";
193: printf("%%%.2f",1.23456789e10);
194:
195: echo"\n\n*** Output for '%%' as the format parameter ***\n";
196: printf("%%",1.23456789e10);
197:
198: echo"\n\n*** Output for precision value more than maximum ***\n";
199: printf("%.988f",1.23456789e10);
200:
201: echo"\n\n*** Output for invalid width(-15) specifier ***\n";
202: printf("%030.-15s", $tempstring);
203:
204: echo"\n\n*** Output for '%F' as the format parameter ***\n";
205: printf("%F",1.23456789e10);
206:
207: echo"\n\n*** Output for '%X' as the format parameter ***\n";
208: printf("%X",12);
209:
210: echo"\n\n*** Output with no format parameter ***\n";
211: printf($tempnum);
212:
213: echo"\n\n*** Output for multiple format parameters ***\n";
214: printf("%d %s %d\n", $tempnum, $tempstring, $tempnum);
215:
216: echo"\n\n*** Output for excess of mixed type arguments ***\n";
217: printf("%s", $tempstring, $tempstring, $tempstring);
218:
219: echo"\n\n*** Output for string format parameter and integer type argument ***\n";
220: printf("%s", $tempnum);
221:
222: echo"\n\n*** Output for integer format parameter and string type argument ***\n";
223: printf("%d", $tempstring);
224:
225:
226: ?>
227: --EXPECTF--
228: *** Output for zero argument ***
229:
230: Warning: printf() expects at least 1 parameter, 0 given in %s on line %d
231:
232: *** Output for insufficient number of arguments ***
233:
234: Warning: printf(): Too few arguments in %s on line %d
235:
236: *** Output for scalar argument ***
237: 3
238: *** Output for NULL as argument ***
239:
240:
241: *** Output for float type ***
242:
243: Input Float numbers variation array is:
244: Array
245: (
246: [0] => 0
247: [1] => 1
248: [2] => -1
249: [3] => 0.32
250: [4] => -0.32
251: [5] => 3.4-3.4
252: [6] => 2.54
253: [7] => -2.54
254: [8] => 1.2345678E+99
255: [9] => -1.2345678E+99
256: )
257:
258:
259: Float Iteration 1
260: 0.000000
261: 1.000000
262: -1.000000
263: 0.320000
264: -0.320000
265: 3.400000
266: 2.540000
267: -2.540000
268: 1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.000000
269: -1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.000000
270:
271: Float Iteration 2
272: 0.000000
273: 1.000000
274: -1.000000
275: 0.320000
276: -0.320000
277: 3.400000
278: 2.540000
279: -2.540000
280: 1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.000000
281: -1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.000000
282:
283: Float Iteration 3
284: +0.000000
285: +1.000000
286: -1.000000
287: +0.320000
288: -0.320000
289: +3.400000
290: +2.540000
291: -2.540000
292: +1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.000000
293: -1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.000000
294:
295: Float Iteration 4
296: 0.00
297: 1.00
298: -1.00
299: 0.32
300: -0.32
301: 3.40
302: 2.54
303: -2.54
304: 1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.00
305: -1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.00
306:
307: Float Iteration 5
308: 0.00
309: 1.00
310: -1.00
311: 0.32
312: -0.32
313: 3.40
314: 2.54
315: -2.54
316: 1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.00
317: -1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.00
318:
319: Float Iteration 6
320: 0000.00
321: 0001.00
322: -001.00
323: 0000.32
324: -000.32
325: 0003.40
326: 0002.54
327: -002.54
328: 1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.00
329: -1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.00
330:
331: Float Iteration 7
332: 0.00000
333: 1.00000
334: -1.0000
335: 0.32000
336: -0.3200
337: 3.40000
338: 2.54000
339: -2.5400
340: 1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.00
341: -1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.00
342:
343: Float Iteration 8
344: ###0.00
345: ###1.00
346: ##-1.00
347: ###0.32
348: ##-0.32
349: ###3.40
350: ###2.54
351: ##-2.54
352: 1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.00
353: -1234567799999999974395005011934353453808157274826416694779123657996479008398428960266851879135215616.00
354:
355: *** Output for integer type ***
356:
357: Input Integer numbers variation array is:
358: Array
359: (
360: [0] => 0
361: [1] => 1
362: [2] => -1
363: [3] => 2.7
364: [4] => -2.7
365: [5] => 23333333
366: [6] => -23333333
367: [7] => 1234
368: )
369:
370:
371: Integer Iteration 1
372: 0
373: 1
374: -1
375: 2
376: -2
377: 23333333
378: -23333333
379: 1234
380:
381: Integer Iteration 2
382: 0
383: 1
384: -1
385: 2
386: -2
387: 23333333
388: -23333333
389: 1234
390:
391: Integer Iteration 3
392: +0
393: +1
394: -1
395: +2
396: -2
397: +23333333
398: -23333333
399: +1234
400:
401: Integer Iteration 4
402: 0
403: 1
404: -1
405: 2
406: -2
407: 23333333
408: -23333333
409: 1234
410:
411: Integer Iteration 5
412: 0
413: 1
414: -1
415: 2
416: -2
417: 23333333
418: -23333333
419: 1234
420:
421: Integer Iteration 6
422: 0000000
423: 0000001
424: -000001
425: 0000002
426: -000002
427: 23333333
428: -23333333
429: 0001234
430:
431: Integer Iteration 7
432: 0
433: 1
434: -1
435: 2
436: -2
437: 23333333
438: -23333333
439: 1234
440:
441: Integer Iteration 8
442: ######0
443: ######1
444: #####-1
445: ######2
446: #####-2
447: 23333333
448: -23333333
449: ###1234
450:
451: *** Output for binary type ***
452:
453: Input numbers variation array is:
454: Array
455: (
456: [0] => 0
457: [1] => 1
458: [2] => -1
459: [3] => 2.7
460: [4] => -2.7
461: [5] => 23333333
462: [6] => -23333333
463: [7] => 1234
464: )
465:
466: 0
467: 1
468: 1111111111111111111111111111111111111111111111111111111111111111
469: 10
470: 1111111111111111111111111111111111111111111111111111111111111110
471: 1011001000000100111010101
472: 1111111111111111111111111111111111111110100110111111011000101011
473: 10011010010
474:
475: *** Output for char type ***
476:
477: Input Characters variation array is:
478: Array
479: (
480: [0] => a
481: [1] => a
482: [2] => 67
483: [3] => -67
484: [4] => 99
485: )
486:
487: