sqrt_variation.phpt 1017 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --TEST--
  2. Test variations in usage of sqrt()
  3. --INI--
  4. precision = 14
  5. --FILE--
  6. <?php
  7. /*
  8. * proto float sqrt(float number)
  9. * Function is implemented in ext/standard/math.c
  10. */
  11. //Test sqrt with a different input values
  12. echo "*** Testing sqrt() : usage variations ***\n";
  13. $values = array(23,
  14. -23,
  15. 2.345e1,
  16. -2.345e1,
  17. 0x17,
  18. 027,
  19. "23",
  20. "23.45",
  21. "2.345e1",
  22. "nonsense",
  23. "1000",
  24. "1000ABC",
  25. null,
  26. true,
  27. false);
  28. for ($i = 0; $i < count($values); $i++) {
  29. $res = sqrt($values[$i]);
  30. var_dump($res);
  31. }
  32. ?>
  33. ===Done===
  34. --EXPECTF--
  35. *** Testing sqrt() : usage variations ***
  36. float(4.7958315233127)
  37. float(NAN)
  38. float(4.8425200051213)
  39. float(NAN)
  40. float(4.7958315233127)
  41. float(4.7958315233127)
  42. float(4.7958315233127)
  43. float(4.8425200051213)
  44. float(4.8425200051213)
  45. Warning: sqrt() expects parameter 1 to be double, string given in %s on line %d
  46. NULL
  47. float(31.622776601684)
  48. Notice: A non well formed numeric value encountered in %s on line %d
  49. float(31.622776601684)
  50. float(0)
  51. float(1)
  52. float(0)
  53. ===Done===