vprintf_variation5.phpt 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. --TEST--
  2. Test vprintf() function : usage variations - float formats with float values
  3. --FILE--
  4. <?php
  5. /* Prototype : string vprintf(string format, array args)
  6. * Description: Output a formatted string
  7. * Source code: ext/standard/formatted_print.c
  8. */
  9. /*
  10. * Test vprintf() when different float formats and float values are passed to
  11. * the '$format' and '$args' arguments of the function
  12. */
  13. echo "*** Testing vprintf() : int formats with float values ***\n";
  14. // defining array of float formats
  15. $formats = array(
  16. "%f",
  17. "%+f %-f %F",
  18. "%lf %Lf, %4f %-4f",
  19. "%10.4f %-10.4F %04f %04.4f",
  20. "%'#2f %'2f %'$2f %'_2f",
  21. "%f %f %f %f",
  22. "% %%f f%",
  23. '%3$f %4$f %1$f %2$f'
  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, -2147483647, +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, 01293),
  34. array(1234.1234, -5678.5678, 2345.2345),
  35. array(3.33, 4.44, 1.11, 2.22)
  36. );
  37. // looping to test vprintf() with different float formats from the above $format array
  38. // and with float values from the above $args_array array
  39. $counter = 1;
  40. foreach($formats as $format) {
  41. echo "\n-- Iteration $counter --\n";
  42. $result = vprintf($format, $args_array[$counter-1]);
  43. echo "\n";
  44. var_dump($result);
  45. $counter++;
  46. }
  47. ?>
  48. ===DONE===
  49. --EXPECT--
  50. *** Testing vprintf() : int formats with float values ***
  51. -- Iteration 1 --
  52. 0.000000
  53. int(8)
  54. -- Iteration 2 --
  55. -0.100000 0.100000 10.000001
  56. int(28)
  57. -- Iteration 3 --
  58. 2147483649.000000 f, 2147483640.000000 -2147483640.000000
  59. int(57)
  60. -- Iteration 4 --
  61. 200000.0000 0.0000 -200000.000000 -0.0000
  62. int(45)
  63. -- Iteration 5 --
  64. 20000.000000 -1999999999999999879418332743206357172224.000000 0.000000 20000000000000000000.000000
  65. int(98)
  66. -- Iteration 6 --
  67. 4667.000000 4011.000000 83.000000 10.000000
  68. int(43)
  69. -- Iteration 7 --
  70. %-5678.567800 f
  71. int(15)
  72. -- Iteration 8 --
  73. 1.110000 2.220000 3.330000 4.440000
  74. int(35)
  75. ===DONE===