vprintf_variation5.phpt 1.9 KB

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