From 4b1718825066fecfe4c5cd5f26076a203c4c4849 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Thu, 13 May 2021 15:22:37 +0200 Subject: [PATCH] That should be most of the trig implementation functions grouped and methods renamed for clarity --- .../Calculation/Calculation.php | 26 ++-- src/PhpSpreadsheet/Calculation/MathTrig.php | 78 +++++------ .../Calculation/MathTrig/Acot.php | 28 ---- .../Calculation/MathTrig/Acoth.php | 30 ----- .../Calculation/MathTrig/Atan.php | 28 ---- .../Calculation/MathTrig/Atan2.php | 46 ------- .../Calculation/MathTrig/Atanh.php | 28 ---- .../Calculation/MathTrig/Cot.php | 28 ---- .../Calculation/MathTrig/Coth.php | 28 ---- .../Calculation/MathTrig/Csc.php | 28 ---- .../Calculation/MathTrig/Csch.php | 28 ---- .../Calculation/MathTrig/Sec.php | 28 ---- .../Calculation/MathTrig/Sech.php | 28 ---- .../Calculation/MathTrig/Tan.php | 28 ---- .../Calculation/MathTrig/Tanh.php | 28 ---- .../Calculation/MathTrig/Trig/Cosecant.php | 49 +++++++ .../Calculation/MathTrig/Trig/Cotangent.php | 91 +++++++++++++ .../Calculation/MathTrig/Trig/Secant.php | 49 +++++++ .../Calculation/MathTrig/Trig/Tangent.php | 127 ++++++++++++++++++ 19 files changed, 368 insertions(+), 436 deletions(-) delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Acot.php delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Acoth.php delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Atan.php delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Atan2.php delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Atanh.php delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Cot.php delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Coth.php delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Csc.php delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Csch.php delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Sec.php delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Sech.php delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Tan.php delete mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Tanh.php create mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cosecant.php create mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cotangent.php create mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Trig/Secant.php create mode 100644 src/PhpSpreadsheet/Calculation/MathTrig/Trig/Tangent.php diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index 5d357e6c..00b8c22e 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -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' => [ diff --git a/src/PhpSpreadsheet/Calculation/MathTrig.php b/src/PhpSpreadsheet/Calculation/MathTrig.php index e2775ee3..8c26ec70 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig.php @@ -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); } /** diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Acot.php b/src/PhpSpreadsheet/Calculation/MathTrig/Acot.php deleted file mode 100644 index 5817407b..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Acot.php +++ /dev/null @@ -1,28 +0,0 @@ -getMessage(); - } - - return (M_PI / 2) - atan($number); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Acoth.php b/src/PhpSpreadsheet/Calculation/MathTrig/Acoth.php deleted file mode 100644 index 17fe618d..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Acoth.php +++ /dev/null @@ -1,30 +0,0 @@ -getMessage(); - } - - $result = ($number === 1) ? NAN : (log(($number + 1) / ($number - 1)) / 2); - - return Helpers::numberOrNan($result); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Atan.php b/src/PhpSpreadsheet/Calculation/MathTrig/Atan.php deleted file mode 100644 index 1b4cf43d..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Atan.php +++ /dev/null @@ -1,28 +0,0 @@ -getMessage(); - } - - return Helpers::numberOrNan(atan($number)); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Atan2.php b/src/PhpSpreadsheet/Calculation/MathTrig/Atan2.php deleted file mode 100644 index b2cf8bf5..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Atan2.php +++ /dev/null @@ -1,46 +0,0 @@ -getMessage(); - } - - if (($xCoordinate == 0) && ($yCoordinate == 0)) { - return Functions::DIV0(); - } - - return atan2($yCoordinate, $xCoordinate); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Atanh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Atanh.php deleted file mode 100644 index 83045441..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Atanh.php +++ /dev/null @@ -1,28 +0,0 @@ -getMessage(); - } - - return Helpers::numberOrNan(atanh($number)); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Cot.php b/src/PhpSpreadsheet/Calculation/MathTrig/Cot.php deleted file mode 100644 index 53973444..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Cot.php +++ /dev/null @@ -1,28 +0,0 @@ -getMessage(); - } - - return Helpers::verySmallDenominator(cos($angle), sin($angle)); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Coth.php b/src/PhpSpreadsheet/Calculation/MathTrig/Coth.php deleted file mode 100644 index 41e08f85..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Coth.php +++ /dev/null @@ -1,28 +0,0 @@ -getMessage(); - } - - return Helpers::verySmallDenominator(1.0, tanh($angle)); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Csc.php b/src/PhpSpreadsheet/Calculation/MathTrig/Csc.php deleted file mode 100644 index 125963ef..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Csc.php +++ /dev/null @@ -1,28 +0,0 @@ -getMessage(); - } - - return Helpers::verySmallDenominator(1.0, sin($angle)); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Csch.php b/src/PhpSpreadsheet/Calculation/MathTrig/Csch.php deleted file mode 100644 index b1543ec3..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Csch.php +++ /dev/null @@ -1,28 +0,0 @@ -getMessage(); - } - - return Helpers::verySmallDenominator(1.0, sinh($angle)); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sec.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sec.php deleted file mode 100644 index d20b6375..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Sec.php +++ /dev/null @@ -1,28 +0,0 @@ -getMessage(); - } - - return Helpers::verySmallDenominator(1.0, cos($angle)); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sech.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sech.php deleted file mode 100644 index 6bb0469f..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Sech.php +++ /dev/null @@ -1,28 +0,0 @@ -getMessage(); - } - - return Helpers::verySmallDenominator(1.0, cosh($angle)); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Tan.php b/src/PhpSpreadsheet/Calculation/MathTrig/Tan.php deleted file mode 100644 index 2b1a0ac0..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Tan.php +++ /dev/null @@ -1,28 +0,0 @@ -getMessage(); - } - - return Helpers::verySmallDenominator(sin($angle), cos($angle)); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Tanh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Tanh.php deleted file mode 100644 index f07f8748..00000000 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Tanh.php +++ /dev/null @@ -1,28 +0,0 @@ -getMessage(); - } - - return tanh($angle); - } -} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cosecant.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cosecant.php new file mode 100644 index 00000000..3038e6cc --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cosecant.php @@ -0,0 +1,49 @@ +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)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cotangent.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cotangent.php new file mode 100644 index 00000000..1b796f50 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cotangent.php @@ -0,0 +1,91 @@ +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); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Secant.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Secant.php new file mode 100644 index 00000000..70299cb7 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Secant.php @@ -0,0 +1,49 @@ +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)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Tangent.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Tangent.php new file mode 100644 index 00000000..6cd235fb --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Tangent.php @@ -0,0 +1,127 @@ +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); + } +}