Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 400 and 401]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Trig;
   4  
   5  use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
   6  use PhpOffice\PhpSpreadsheet\Calculation\Exception;
   7  use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Helpers;
   8  
   9  class Cotangent
  10  {
  11      use ArrayEnabled;
  12  
  13      /**
  14       * COT.
  15       *
  16       * Returns the cotangent of an angle.
  17       *
  18       * @param array|float $angle Number, or can be an array of numbers
  19       *
  20       * @return array|float|string The cotangent of the angle
  21       *         If an array of numbers is passed as the argument, then the returned result will also be an array
  22       *            with the same dimensions
  23       */
  24      public static function cot($angle)
  25      {
  26          if (is_array($angle)) {
  27              return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $angle);
  28          }
  29  
  30          try {
  31              $angle = Helpers::validateNumericNullBool($angle);
  32          } catch (Exception $e) {
  33              return $e->getMessage();
  34          }
  35  
  36          return Helpers::verySmallDenominator(cos($angle), sin($angle));
  37      }
  38  
  39      /**
  40       * COTH.
  41       *
  42       * Returns the hyperbolic cotangent of an angle.
  43       *
  44       * @param array|float $angle Number, or can be an array of numbers
  45       *
  46       * @return array|float|string The hyperbolic cotangent of the angle
  47       *         If an array of numbers is passed as the argument, then the returned result will also be an array
  48       *            with the same dimensions
  49       */
  50      public static function coth($angle)
  51      {
  52          if (is_array($angle)) {
  53              return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $angle);
  54          }
  55  
  56          try {
  57              $angle = Helpers::validateNumericNullBool($angle);
  58          } catch (Exception $e) {
  59              return $e->getMessage();
  60          }
  61  
  62          return Helpers::verySmallDenominator(1.0, tanh($angle));
  63      }
  64  
  65      /**
  66       * ACOT.
  67       *
  68       * Returns the arccotangent of a number.
  69       *
  70       * @param array|float $number Number, or can be an array of numbers
  71       *
  72       * @return array|float|string The arccotangent of the number
  73       *         If an array of numbers is passed as the argument, then the returned result will also be an array
  74       *            with the same dimensions
  75       */
  76      public static function acot($number)
  77      {
  78          if (is_array($number)) {
  79              return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $number);
  80          }
  81  
  82          try {
  83              $number = Helpers::validateNumericNullBool($number);
  84          } catch (Exception $e) {
  85              return $e->getMessage();
  86          }
  87  
  88          return (M_PI / 2) - atan($number);
  89      }
  90  
  91      /**
  92       * ACOTH.
  93       *
  94       * Returns the hyperbolic arccotangent of a number.
  95       *
  96       * @param array|float $number Number, or can be an array of numbers
  97       *
  98       * @return array|float|string The hyperbolic arccotangent of the number
  99       *         If an array of numbers is passed as the argument, then the returned result will also be an array
 100       *            with the same dimensions
 101       */
 102      public static function acoth($number)
 103      {
 104          if (is_array($number)) {
 105              return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $number);
 106          }
 107  
 108          try {
 109              $number = Helpers::validateNumericNullBool($number);
 110          } catch (Exception $e) {
 111              return $e->getMessage();
 112          }
 113  
 114          $result = ($number === 1) ? NAN : (log(($number + 1) / ($number - 1)) / 2);
 115  
 116          return Helpers::numberOrNan($result);
 117      }
 118  }