log.phpt 859 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --TEST--
  2. log() tests
  3. --FILE--
  4. <?php
  5. echo "On failure, please mail result to php-dev@lists.php.net\n";
  6. for ($x = 0, $count= 0; $x < 200; $x++) {
  7. $x2 = (int) exp(log($x));
  8. // e ^ log(x) should be close in range to x
  9. if (($x2 < ($x + 2)) && ($x2 > ($x - 2))) {
  10. $count++;
  11. } else {
  12. print "$x : $x2\n";
  13. }
  14. }
  15. print $count . "\n";
  16. // Now test the base form of log
  17. for ($base = 2; $base < 11; $base++) {
  18. for ($x = 0, $count= 0; $x < 50; $x++) {
  19. $x2 = (int) pow($base, log($x, $base));
  20. // base ^ log(x) should be close in range to x
  21. if (($x2 < ($x + 2)) && ($x2 > ($x - 2))) {
  22. $count++;
  23. } else {
  24. print "base $base: $x : $x2\n";
  25. }
  26. }
  27. print $count . "\n";
  28. }
  29. ?>
  30. --EXPECT--
  31. On failure, please mail result to php-dev@lists.php.net
  32. 200
  33. 50
  34. 50
  35. 50
  36. 50
  37. 50
  38. 50
  39. 50
  40. 50
  41. 50