1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Trig; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Helpers; |
8
|
|
|
|
9
|
|
|
class Tangent |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* TAN. |
13
|
|
|
* |
14
|
|
|
* Returns the result of builtin function tan after validating args. |
15
|
|
|
* |
16
|
|
|
* @param mixed $angle Should be numeric |
17
|
|
|
* |
18
|
|
|
* @return float|string tangent |
19
|
|
|
*/ |
20
|
13 |
|
public static function tan($angle) |
21
|
|
|
{ |
22
|
|
|
try { |
23
|
13 |
|
$angle = Helpers::validateNumericNullBool($angle); |
24
|
1 |
|
} catch (Exception $e) { |
25
|
1 |
|
return $e->getMessage(); |
26
|
|
|
} |
27
|
|
|
|
28
|
12 |
|
return Helpers::verySmallDenominator(sin($angle), cos($angle)); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* TANH. |
33
|
|
|
* |
34
|
|
|
* Returns the result of builtin function sinh after validating args. |
35
|
|
|
* |
36
|
|
|
* @param mixed $angle Should be numeric |
37
|
|
|
* |
38
|
|
|
* @return float|string hyperbolic tangent |
39
|
|
|
*/ |
40
|
10 |
|
public static function tanh($angle) |
41
|
|
|
{ |
42
|
|
|
try { |
43
|
10 |
|
$angle = Helpers::validateNumericNullBool($angle); |
44
|
1 |
|
} catch (Exception $e) { |
45
|
1 |
|
return $e->getMessage(); |
46
|
|
|
} |
47
|
|
|
|
48
|
9 |
|
return tanh($angle); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* ATAN. |
53
|
|
|
* |
54
|
|
|
* Returns the arctangent of a number. |
55
|
|
|
* |
56
|
|
|
* @param float $number Number |
57
|
|
|
* |
58
|
|
|
* @return float|string The arctangent of the number |
59
|
|
|
*/ |
60
|
12 |
|
public static function atan($number) |
61
|
|
|
{ |
62
|
|
|
try { |
63
|
12 |
|
$number = Helpers::validateNumericNullBool($number); |
64
|
1 |
|
} catch (Exception $e) { |
65
|
1 |
|
return $e->getMessage(); |
66
|
|
|
} |
67
|
|
|
|
68
|
11 |
|
return Helpers::numberOrNan(atan($number)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* ATANH. |
73
|
|
|
* |
74
|
|
|
* Returns the inverse hyperbolic tangent of a number. |
75
|
|
|
* |
76
|
|
|
* @param float $number Number |
77
|
|
|
* |
78
|
|
|
* @return float|string The inverse hyperbolic tangent of the number |
79
|
|
|
*/ |
80
|
11 |
|
public static function atanh($number) |
81
|
|
|
{ |
82
|
|
|
try { |
83
|
11 |
|
$number = Helpers::validateNumericNullBool($number); |
84
|
1 |
|
} catch (Exception $e) { |
85
|
1 |
|
return $e->getMessage(); |
86
|
|
|
} |
87
|
|
|
|
88
|
10 |
|
return Helpers::numberOrNan(atanh($number)); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* ATAN2. |
93
|
|
|
* |
94
|
|
|
* This function calculates the arc tangent of the two variables x and y. It is similar to |
95
|
|
|
* calculating the arc tangent of y ÷ x, except that the signs of both arguments are used |
96
|
|
|
* to determine the quadrant of the result. |
97
|
|
|
* The arctangent is the angle from the x-axis to a line containing the origin (0, 0) and a |
98
|
|
|
* point with coordinates (xCoordinate, yCoordinate). The angle is given in radians between |
99
|
|
|
* -pi and pi, excluding -pi. |
100
|
|
|
* |
101
|
|
|
* Note that the Excel ATAN2() function accepts its arguments in the reverse order to the standard |
102
|
|
|
* PHP atan2() function, so we need to reverse them here before calling the PHP atan() function. |
103
|
|
|
* |
104
|
|
|
* Excel Function: |
105
|
|
|
* ATAN2(xCoordinate,yCoordinate) |
106
|
|
|
* |
107
|
|
|
* @param mixed $xCoordinate should be float, the x-coordinate of the point |
108
|
|
|
* @param mixed $yCoordinate should be float, the y-coordinate of the point |
109
|
|
|
* |
110
|
|
|
* @return float|string the inverse tangent of the specified x- and y-coordinates, or a string containing an error |
111
|
|
|
*/ |
112
|
19 |
|
public static function atan2($xCoordinate, $yCoordinate) |
113
|
|
|
{ |
114
|
|
|
try { |
115
|
19 |
|
$xCoordinate = Helpers::validateNumericNullBool($xCoordinate); |
116
|
18 |
|
$yCoordinate = Helpers::validateNumericNullBool($yCoordinate); |
117
|
2 |
|
} catch (Exception $e) { |
118
|
2 |
|
return $e->getMessage(); |
119
|
|
|
} |
120
|
|
|
|
121
|
17 |
|
if (($xCoordinate == 0) && ($yCoordinate == 0)) { |
122
|
2 |
|
return Functions::DIV0(); |
123
|
|
|
} |
124
|
|
|
|
125
|
15 |
|
return atan2($yCoordinate, $xCoordinate); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|