Code Coverage for /src/SciPhp/NumPhp/Mathematical/TrigonometricTrait.php

 
Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
TrigonometricTrait
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 cos
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 sin
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 tan
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
1 <?php
2
3 declare(strict_types=1);
4
5 namespace SciPhp\NumPhp\Mathematical;
6
7 /**
8  * Trigonometric methods
9  */
10 trait TrigonometricTrait
11 {
12     /**
13      * Cosine element-wise.
14      *
15      * @param  \SciPhp\NdArray|array|int|float $m
16      * @return \SciPhp\NdArray|int|float
17      * @link http://sciphp.org/numphp.cos Documentation
18      * @since 0.4.0
19      * @api
20      */
21     final public static function cos($m)
22     {
23         if (\is_numeric($m)) {
24             return cos($m);
25         }
26
27         static::transform($m, true);
28
29         $func = static function (&$element): void {
30             $element = cos($element);
31         };
32
33         return $m->copy()->walk_recursive($func);
34     }
35
36     /**
37      * Trigonometric sine, element-wise.
38      *
39      * @param  \SciPhp\NdArray|array|int|float $m
40      * @return \SciPhp\NdArray|int|float
41      * @link http://sciphp.org/numphp.sin Documentation
42      * @since 0.4.0
43      * @api
44      */
45     final public static function sin($m)
46     {
47         if (\is_numeric($m)) {
48             return sin($m);
49         }
50
51         static::transform($m, true);
52
53         $func = static function (&$element): void {
54             $element = sin($element);
55         };
56
57         return $m->copy()->walk_recursive($func);
58     }
59
60     /**
61      * Compute tangent element-wise.
62      *
63      * Equivalent to np::sin(x)->divide(np::cos(x)) element-wise.
64      *
65      * @param  \SciPhp\NdArray|array|int|float $m
66      * @return \SciPhp\NdArray|int|float
67      * @link http://sciphp.org/numphp.tan Documentation
68      * @since 0.5.0
69      * @api
70      */
71     final public static function tan($m)
72     {
73         if (\is_numeric($m)) {
74             return tan($m);
75         }
76
77         static::transform($m, true);
78
79         $func = static function (&$element): void {
80             $element = tan($element);
81         };
82
83         return $m->copy()->walk_recursive($func);
84     }
85 }