-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathlog.php
35 lines (27 loc) · 776 Bytes
/
log.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace Psl\Math;
use function log as php_log;
/**
* Returns the logarithm of the given number.
*
* @pure
*
* @throws Exception\InvalidArgumentException If $number or $base are negative, or $base is equal to 1.0.
*/
function log(float $number, null|float $base = null): float
{
if ($number <= 0) {
throw new Exception\InvalidArgumentException('$number must be positive.');
}
if (null === $base) {
return php_log($number);
}
if ($base <= 0) {
throw new Exception\InvalidArgumentException('$base must be positive.');
}
if ($base === 1.0) {
throw new Exception\InvalidArgumentException('Logarithm undefined for $base of 1.0.');
}
return php_log($number, $base);
}