That should be most of the trig implementation functions grouped and methods renamed for clarity

This commit is contained in:
MarkBaker 2021-05-13 15:22:37 +02:00 committed by Mark Baker
parent 0c26333e96
commit 4b17188250
19 changed files with 368 additions and 436 deletions

View File

@ -256,12 +256,12 @@ class Calculation
],
'ACOT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Acot::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Cotangent::class, 'acot'],
'argumentCount' => '1',
],
'ACOTH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Acoth::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Cotangent::class, 'acoth'],
'argumentCount' => '1',
],
'ADDRESS' => [
@ -316,17 +316,17 @@ class Calculation
],
'ATAN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Atan::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Tangent::class, 'atan'],
'argumentCount' => '1',
],
'ATAN2' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Atan2::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Tangent::class, 'atan2'],
'argumentCount' => '2',
],
'ATANH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Atanh::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Tangent::class, 'atanh'],
'argumentCount' => '1',
],
'AVEDEV' => [
@ -618,12 +618,12 @@ class Calculation
],
'COT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Cot::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Cotangent::class, 'cot'],
'argumentCount' => '1',
],
'COTH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Coth::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Cotangent::class, 'coth'],
'argumentCount' => '1',
],
'COUNT' => [
@ -703,12 +703,12 @@ class Calculation
],
'CSC' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Csc::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Cosecant::class, 'csc'],
'argumentCount' => '1',
],
'CSCH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Csch::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Cosecant::class, 'csch'],
'argumentCount' => '1',
],
'CUBEKPIMEMBER' => [
@ -2168,12 +2168,12 @@ class Calculation
],
'SEC' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Sec::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Secant::class, 'sec'],
'argumentCount' => '1',
],
'SECH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Sech::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Secant::class, 'sech'],
'argumentCount' => '1',
],
'SECOND' => [
@ -2369,12 +2369,12 @@ class Calculation
],
'TAN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Tan::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Tangent::class, 'tan'],
'argumentCount' => '1',
],
'TANH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig\Tanh::class, 'evaluate'],
'functionCall' => [MathTrig\Trig\Tangent::class, 'tanh'],
'argumentCount' => '1',
],
'TBILLEQ' => [

View File

@ -47,8 +47,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Atan2::evaluate()
* Use the evaluate method in the MathTrig\Atan2 class instead
* @See MathTrig\Trig\Tangent::atan2()
* Use the atan2 method in the MathTrig\Trig\Tangent class instead
*
* @param float $xCoordinate the x-coordinate of the point
* @param float $yCoordinate the y-coordinate of the point
@ -57,7 +57,7 @@ class MathTrig
*/
public static function ATAN2($xCoordinate = null, $yCoordinate = null)
{
return MathTrig\Atan2::evaluate($xCoordinate, $yCoordinate);
return MathTrig\Trig\Tangent::atan2($xCoordinate, $yCoordinate);
}
/**
@ -955,8 +955,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Sec::evaluate()
* Use the evaluate method in the MathTrig\Sec class instead
* @See MathTrig\Trig\Secant::sec()
* Use the sec method in the MathTrig\Trig\Secant class instead
*
* @param float $angle Number
*
@ -964,7 +964,7 @@ class MathTrig
*/
public static function SEC($angle)
{
return MathTrig\Sec::evaluate($angle);
return MathTrig\Trig\Secant::sec($angle);
}
/**
@ -974,8 +974,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\SecH::evaluate()
* Use the evaluate method in the MathTrig\Sech class instead
* @See MathTrig\Trig\Secant::sech()
* Use the sech method in the MathTrig\Trig\Secant class instead
*
* @param float $angle Number
*
@ -983,7 +983,7 @@ class MathTrig
*/
public static function SECH($angle)
{
return MathTrig\Sech::evaluate($angle);
return MathTrig\Trig\Secant::sech($angle);
}
/**
@ -993,8 +993,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Csc::evaluate()
* Use the evaluate method in the MathTrig\Csc class instead
* @See MathTrig\Trig\Cosecant::csc()
* Use the csc method in the MathTrig\Trig\Cosecant class instead
*
* @param float $angle Number
*
@ -1002,7 +1002,7 @@ class MathTrig
*/
public static function CSC($angle)
{
return MathTrig\Csc::evaluate($angle);
return MathTrig\Trig\Cosecant::csc($angle);
}
/**
@ -1012,8 +1012,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Csch::evaluate()
* Use the evaluate method in the MathTrig\Csch class instead
* @See MathTrig\Trig\Cosecant::csch()
* Use the csch method in the MathTrig\Trig\Cosecant class instead
*
* @param float $angle Number
*
@ -1021,7 +1021,7 @@ class MathTrig
*/
public static function CSCH($angle)
{
return MathTrig\Csch::evaluate($angle);
return MathTrig\Trig\Cosecant::csch($angle);
}
/**
@ -1031,8 +1031,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Cot::evaluate()
* Use the evaluate method in the MathTrig\Cot class instead
* @See MathTrig\Trig\Cotangent::cot()
* Use the cot method in the MathTrig\Trig\Cotangent class instead
*
* @param float $angle Number
*
@ -1040,7 +1040,7 @@ class MathTrig
*/
public static function COT($angle)
{
return MathTrig\Cot::evaluate($angle);
return MathTrig\Trig\Cotangent::cot($angle);
}
/**
@ -1050,8 +1050,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Coth::evaluate()
* Use the evaluate method in the MathTrig\Coth class instead
* @See MathTrig\Trig\Cotangent::coth()
* Use the coth method in the MathTrig\Trig\Cotangent class instead
*
* @param float $angle Number
*
@ -1059,7 +1059,7 @@ class MathTrig
*/
public static function COTH($angle)
{
return MathTrig\Coth::evaluate($angle);
return MathTrig\Trig\Cotangent::coth($angle);
}
/**
@ -1069,8 +1069,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Acot::evaluate()
* Use the evaluate method in the MathTrig\Acot class instead
* @See MathTrig\Trig\Cotangent::acot()
* Use the acot method in the MathTrig\Trig\Cotangent class instead
*
* @param float $number Number
*
@ -1078,7 +1078,7 @@ class MathTrig
*/
public static function ACOT($number)
{
return MathTrig\Acot::evaluate($number);
return MathTrig\Trig\Cotangent::acot($number);
}
/**
@ -1105,8 +1105,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Acoth::evaluate()
* Use the evaluate method in the MathTrig\Acoth class instead
* @See MathTrig\Trig\Cotangent::acoth()
* Use the acoth method in the MathTrig\Trig\Cotangent class instead
*
* @param float $number Number
*
@ -1114,7 +1114,7 @@ class MathTrig
*/
public static function ACOTH($number)
{
return MathTrig\Acoth::evaluate($number);
return MathTrig\Trig\Cotangent::acoth($number);
}
/**
@ -1239,8 +1239,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Atan::evaluate()
* Use the evaluate method in the MathTrig\Atan class instead
* @See MathTrig\Trig\Tangent::atan()
* Use the atan method in the MathTrig\Trig\Tangent class instead
*
* @param mixed $number Should be numeric
*
@ -1248,7 +1248,7 @@ class MathTrig
*/
public static function builtinATAN($number)
{
return MathTrig\Atan::evaluate($number);
return MathTrig\Trig\Tangent::atan($number);
}
/**
@ -1258,8 +1258,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Atanh::evaluate()
* Use the evaluate method in the MathTrig\Atanh class instead
* @See MathTrig\Trig\Tangent::atanh()
* Use the atanh method in the MathTrig\Trig\Tangent class instead
*
* @param mixed $number Should be numeric
*
@ -1267,7 +1267,7 @@ class MathTrig
*/
public static function builtinATANH($number)
{
return MathTrig\Atanh::evaluate($number);
return MathTrig\Trig\Tangent::atanh($number);
}
/**
@ -1467,8 +1467,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Tan::evaluate()
* Use the evaluate method in the MathTrig\Tan class instead
* @See MathTrig\Trig\Tangent::tan()
* Use the tan method in the MathTrig\Trig\Tangent class instead
*
* @param mixed $number Should be numeric
*
@ -1476,7 +1476,7 @@ class MathTrig
*/
public static function builtinTAN($number)
{
return MathTrig\Tan::evaluate($number);
return MathTrig\Trig\Tangent::tan($number);
}
/**
@ -1486,8 +1486,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
* @See MathTrig\Tan::evaluate()
* Use the evaluate method in the MathTrig\Tanh class instead
* @See MathTrig\Trig\Tangent::tanh()
* Use the tanh method in the MathTrig\Trig\Tangent class instead
*
* @param mixed $number Should be numeric
*
@ -1495,7 +1495,7 @@ class MathTrig
*/
public static function builtinTANH($number)
{
return MathTrig\Tanh::evaluate($number);
return MathTrig\Trig\Tangent::tanh($number);
}
/**

View File

@ -1,28 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Acot
{
/**
* ACOT.
*
* Returns the arccotangent of a number.
*
* @param float $number Number
*
* @return float|string The arccotangent of the number
*/
public static function evaluate($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return (M_PI / 2) - atan($number);
}
}

View File

@ -1,30 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Acoth
{
/**
* ACOTH.
*
* Returns the hyperbolic arccotangent of a number.
*
* @param float $number Number
*
* @return float|string The hyperbolic arccotangent of the number
*/
public static function evaluate($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
$result = ($number === 1) ? NAN : (log(($number + 1) / ($number - 1)) / 2);
return Helpers::numberOrNan($result);
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Atan
{
/**
* ATAN.
*
* Returns the arctangent of a number.
*
* @param float $number Number
*
* @return float|string The arctangent of the number
*/
public static function evaluate($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::numberOrNan(atan($number));
}
}

View File

@ -1,46 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Atan2
{
/**
* ATAN2.
*
* This function calculates the arc tangent of the two variables x and y. It is similar to
* calculating the arc tangent of y ÷ x, except that the signs of both arguments are used
* to determine the quadrant of the result.
* The arctangent is the angle from the x-axis to a line containing the origin (0, 0) and a
* point with coordinates (xCoordinate, yCoordinate). The angle is given in radians between
* -pi and pi, excluding -pi.
*
* Note that the Excel ATAN2() function accepts its arguments in the reverse order to the standard
* PHP atan2() function, so we need to reverse them here before calling the PHP atan() function.
*
* Excel Function:
* ATAN2(xCoordinate,yCoordinate)
*
* @param mixed $xCoordinate should be float, the x-coordinate of the point
* @param mixed $yCoordinate should be float, the y-coordinate of the point
*
* @return float|string the inverse tangent of the specified x- and y-coordinates, or a string containing an error
*/
public static function evaluate($xCoordinate, $yCoordinate)
{
try {
$xCoordinate = Helpers::validateNumericNullBool($xCoordinate);
$yCoordinate = Helpers::validateNumericNullBool($yCoordinate);
} catch (Exception $e) {
return $e->getMessage();
}
if (($xCoordinate == 0) && ($yCoordinate == 0)) {
return Functions::DIV0();
}
return atan2($yCoordinate, $xCoordinate);
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Atanh
{
/**
* ATANH.
*
* Returns the arc hyperbolic tangent of a number.
*
* @param float $number Number
*
* @return float|string The arc hyperbolic tangent of the number
*/
public static function evaluate($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::numberOrNan(atanh($number));
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Cot
{
/**
* COT.
*
* Returns the cotangent of an angle.
*
* @param float $angle Number
*
* @return float|string The cotangent of the angle
*/
public static function evaluate($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(cos($angle), sin($angle));
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Coth
{
/**
* COTH.
*
* Returns the hyperbolic cotangent of an angle.
*
* @param float $angle Number
*
* @return float|string The hyperbolic cotangent of the angle
*/
public static function evaluate($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, tanh($angle));
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Csc
{
/**
* CSC.
*
* Returns the cosecant of an angle.
*
* @param float $angle Number
*
* @return float|string The cosecant of the angle
*/
public static function evaluate($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, sin($angle));
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Csch
{
/**
* CSCH.
*
* Returns the hyperbolic cosecant of an angle.
*
* @param float $angle Number
*
* @return float|string The hyperbolic cosecant of the angle
*/
public static function evaluate($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, sinh($angle));
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Sec
{
/**
* SEC.
*
* Returns the secant of an angle.
*
* @param float $angle Number
*
* @return float|string The secant of the angle
*/
public static function evaluate($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, cos($angle));
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Sech
{
/**
* SECH.
*
* Returns the hyperbolic secant of an angle.
*
* @param float $angle Number
*
* @return float|string The hyperbolic secant of the angle
*/
public static function evaluate($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, cosh($angle));
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Tan
{
/**
* TAN.
*
* Returns the result of builtin function tan after validating args.
*
* @param mixed $angle Should be numeric
*
* @return float|string Rounded number
*/
public static function evaluate($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(sin($angle), cos($angle));
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Tanh
{
/**
* TANH.
*
* Returns the result of builtin function sinh after validating args.
*
* @param mixed $angle Should be numeric
*
* @return float|string Rounded number
*/
public static function evaluate($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return tanh($angle);
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Trig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Helpers;
class Cosecant
{
/**
* CSC.
*
* Returns the cosecant of an angle.
*
* @param float $angle Number
*
* @return float|string The cosecant of the angle
*/
public static function csc($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, sin($angle));
}
/**
* CSCH.
*
* Returns the hyperbolic cosecant of an angle.
*
* @param float $angle Number
*
* @return float|string The hyperbolic cosecant of the angle
*/
public static function csch($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, sinh($angle));
}
}

View File

@ -0,0 +1,91 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Trig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Helpers;
class Cotangent
{
/**
* COT.
*
* Returns the cotangent of an angle.
*
* @param float $angle Number
*
* @return float|string The cotangent of the angle
*/
public static function cot($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(cos($angle), sin($angle));
}
/**
* COTH.
*
* Returns the hyperbolic cotangent of an angle.
*
* @param float $angle Number
*
* @return float|string The hyperbolic cotangent of the angle
*/
public static function coth($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, tanh($angle));
}
/**
* ACOT.
*
* Returns the arccotangent of a number.
*
* @param float $number Number
*
* @return float|string The arccotangent of the number
*/
public static function acot($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return (M_PI / 2) - atan($number);
}
/**
* ACOTH.
*
* Returns the hyperbolic arccotangent of a number.
*
* @param float $number Number
*
* @return float|string The hyperbolic arccotangent of the number
*/
public static function acoth($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
$result = ($number === 1) ? NAN : (log(($number + 1) / ($number - 1)) / 2);
return Helpers::numberOrNan($result);
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Trig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Helpers;
class Secant
{
/**
* SEC.
*
* Returns the secant of an angle.
*
* @param float $angle Number
*
* @return float|string The secant of the angle
*/
public static function sec($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, cos($angle));
}
/**
* SECH.
*
* Returns the hyperbolic secant of an angle.
*
* @param float $angle Number
*
* @return float|string The hyperbolic secant of the angle
*/
public static function sech($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, cosh($angle));
}
}

View File

@ -0,0 +1,127 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Trig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Helpers;
class Tangent
{
/**
* TAN.
*
* Returns the result of builtin function tan after validating args.
*
* @param mixed $angle Should be numeric
*
* @return float|string tangent
*/
public static function tan($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(sin($angle), cos($angle));
}
/**
* TANH.
*
* Returns the result of builtin function sinh after validating args.
*
* @param mixed $angle Should be numeric
*
* @return float|string hyperbolic tangent
*/
public static function tanh($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return tanh($angle);
}
/**
* ATAN.
*
* Returns the arctangent of a number.
*
* @param float $number Number
*
* @return float|string The arctangent of the number
*/
public static function atan($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::numberOrNan(atan($number));
}
/**
* ATANH.
*
* Returns the inverse hyperbolic tangent of a number.
*
* @param float $number Number
*
* @return float|string The inverse hyperbolic tangent of the number
*/
public static function atanh($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::numberOrNan(atanh($number));
}
/**
* ATAN2.
*
* This function calculates the arc tangent of the two variables x and y. It is similar to
* calculating the arc tangent of y ÷ x, except that the signs of both arguments are used
* to determine the quadrant of the result.
* The arctangent is the angle from the x-axis to a line containing the origin (0, 0) and a
* point with coordinates (xCoordinate, yCoordinate). The angle is given in radians between
* -pi and pi, excluding -pi.
*
* Note that the Excel ATAN2() function accepts its arguments in the reverse order to the standard
* PHP atan2() function, so we need to reverse them here before calling the PHP atan() function.
*
* Excel Function:
* ATAN2(xCoordinate,yCoordinate)
*
* @param mixed $xCoordinate should be float, the x-coordinate of the point
* @param mixed $yCoordinate should be float, the y-coordinate of the point
*
* @return float|string the inverse tangent of the specified x- and y-coordinates, or a string containing an error
*/
public static function atan2($xCoordinate, $yCoordinate)
{
try {
$xCoordinate = Helpers::validateNumericNullBool($xCoordinate);
$yCoordinate = Helpers::validateNumericNullBool($yCoordinate);
} catch (Exception $e) {
return $e->getMessage();
}
if (($xCoordinate == 0) && ($yCoordinate == 0)) {
return Functions::DIV0();
}
return atan2($yCoordinate, $xCoordinate);
}
}