Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

   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      public static function tan($angle)
  21      {
  22          try {
  23              $angle = Helpers::validateNumericNullBool($angle);
  24          } catch (Exception $e) {
  25              return $e->getMessage();
  26          }
  27  
  28          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      public static function tanh($angle)
  41      {
  42          try {
  43              $angle = Helpers::validateNumericNullBool($angle);
  44          } catch (Exception $e) {
  45              return $e->getMessage();
  46          }
  47  
  48          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      public static function atan($number)
  61      {
  62          try {
  63              $number = Helpers::validateNumericNullBool($number);
  64          } catch (Exception $e) {
  65              return $e->getMessage();
  66          }
  67  
  68          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      public static function atanh($number)
  81      {
  82          try {
  83              $number = Helpers::validateNumericNullBool($number);
  84          } catch (Exception $e) {
  85              return $e->getMessage();
  86          }
  87  
  88          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      public static function atan2($xCoordinate, $yCoordinate)
 113      {
 114          try {
 115              $xCoordinate = Helpers::validateNumericNullBool($xCoordinate);
 116              $yCoordinate = Helpers::validateNumericNullBool($yCoordinate);
 117          } catch (Exception $e) {
 118              return $e->getMessage();
 119          }
 120  
 121          if (($xCoordinate == 0) && ($yCoordinate == 0)) {
 122              return Functions::DIV0();
 123          }
 124  
 125          return atan2($yCoordinate, $xCoordinate);
 126      }
 127  }