Code Coverage for /src/SciPhp/NumPhp/LogarithmTrait.php

 
Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
LogarithmTrait
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 log
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
2
 log10
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 log2
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1 <?php
2
3 declare(strict_types=1);
4
5 namespace SciPhp\NumPhp;
6
7 use Webmozart\Assert\Assert;
8
9 trait LogarithmTrait
10 {
11     /**
12      * Natural logarithm, element-wise.
13      *
14      * @param  \SciPhp\NdArray|array|int|float $m
15      * @param  int|float $base
16      * @return \SciPhp\NdArray|int|float
17      * @link http://sciphp.org/numphp.log Documentation
18      * @api
19      */
20     final public static function log($m, $base = M_E)
21     {
22         Assert::greaterThan($base, 0);
23
24         if (is_numeric($m)) {
25             Assert::greaterThan($m, 0);
26             return log($m, $base);
27         }
28
29         static::transform($m, true);
30
31         $func = static function(&$element) use ($base): void {
32             Assert::greaterThan($element, 0);
33
34             $element = log($element, $base);
35         };
36
37         return $m->copy()->walk_recursive($func);
38     }
39
40     /**
41      * Base 10 logarithm, element-wise.
42      *
43      * @param  \SciPhp\NdArray|array|int|float $m
44      * @return \SciPhp\NdArray|int|float
45      * @link http://sciphp.org/numphp.log10 Documentation
46      * @api
47      */
48     final public static function log10($m)
49     {
50         return self::log($m, 10);
51     }
52
53     /**
54      * Base 2 logarithm, element-wise.
55      *
56      * @param \SciPhp\NdArray|array|int|float $m
57      * @return \SciPhp\NdArray|int|float
58      * @link http://sciphp.org/numphp.log2 Documentation
59      * @api
60      */
61     final public static function log2($m)
62     {
63         return self::log($m, 2);
64     }
65 }