xref: /PHP-8.4/ext/standard/tests/math/log.phpt (revision 782352c5)
1--TEST--
2log() tests
3--FILE--
4<?php
5echo "On failure, please mail result to php-dev@lists.php.net\n";
6for ($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}
15print $count . "\n";
16
17// Now test the base form of log
18for ($base = 2; $base < 11; $base++) {
19    for ($x = 0, $count= 0; $x < 50; $x++) {
20        $x2 = (int) pow($base, log($x, $base));
21        // base ^ log(x) should be close in range to x
22        if (($x2 < ($x + 2)) && ($x2 > ($x - 2))) {
23            $count++;
24        } else {
25             print "base $base: $x : $x2\n";
26        }
27    }
28    print $count . "\n";
29}
30?>
31--EXPECT--
32On failure, please mail result to php-dev@lists.php.net
33200
3450
3550
3650
3750
3850
3950
4050
4150
4250
43