1--TEST--
2Test vprintf() function : usage variations - float formats with float values
3--FILE--
4<?php
5/*
6 * Test vprintf() when different float formats and float values are passed to
7 * the '$format' and '$args' arguments of the function
8*/
9
10echo "*** Testing vprintf() : int formats with float values ***\n";
11
12
13// defining array of float formats
14$formats = array(
15  "%f",
16  "%+f %-f %F",
17  "%lf %4f %-4f",
18  "%10.4f %-10.4F %04f %04.4f",
19  "%'#2f %'2f %'$2f %'_2f",
20  "%f %f %f %f",
21  "% %%f",
22  '%3$f %4$f %1$f %2$f'
23);
24
25// Arrays of float values for the format defined in $format.
26// Each sub array contains float values which correspond to each format string in $format
27$args_array = array(
28  array(0.0),
29  array(-0.1, +0.1, +10.0000006),
30  array(2147483649, +2147483640, -2147483640),
31  array(2e5, 2e-5, -2e5, -2e-5),
32  array(0.2E5, -0.2e40, 0.2E-20, 0.2E+20),
33  array(0x123b, 0xfAb, 0123, 012),
34  array(1234.1234, -5678.5678),
35  array(3.33, 4.44, 1.11, 2.22)
36
37);
38
39// looping to test vprintf() with different float formats from the above $format array
40// and with float values from the above $args_array array
41$counter = 1;
42foreach($formats as $format) {
43  echo "\n-- Iteration $counter --\n";
44  $result = vprintf($format, $args_array[$counter-1]);
45  echo "\n";
46  var_dump($result);
47  $counter++;
48}
49
50?>
51--EXPECT--
52*** Testing vprintf() : int formats with float values ***
53
54-- Iteration 1 --
550.000000
56int(8)
57
58-- Iteration 2 --
59-0.100000 0.100000 10.000001
60int(28)
61
62-- Iteration 3 --
632147483649.000000 2147483640.000000 -2147483640.000000
64int(54)
65
66-- Iteration 4 --
67200000.0000 0.0000     -200000.000000 -0.0000
68int(45)
69
70-- Iteration 5 --
7120000.000000 -1999999999999999879418332743206357172224.000000 0.000000 20000000000000000000.000000
72int(98)
73
74-- Iteration 6 --
754667.000000 4011.000000 83.000000 10.000000
76int(43)
77
78-- Iteration 7 --
79%-5678.567800
80int(13)
81
82-- Iteration 8 --
831.110000 2.220000 3.330000 4.440000
84int(35)
85