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 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   1  <?php
   2  
   3  namespace Complex;
   4  
   5  include(__DIR__ . '/../vendor/autoload.php');
   6  
   7  echo 'Function Examples', PHP_EOL;
   8  
   9  $functions = array(
  10      'abs',
  11      'acos',
  12      'acosh',
  13      'acsc',
  14      'acsch',
  15      'argument',
  16      'asec',
  17      'asech',
  18      'asin',
  19      'asinh',
  20      'conjugate',
  21      'cos',
  22      'cosh',
  23      'csc',
  24      'csch',
  25      'exp',
  26      'inverse',
  27      'ln',
  28      'log2',
  29      'log10',
  30      'rho',
  31      'sec',
  32      'sech',
  33      'sin',
  34      'sinh',
  35      'sqrt',
  36      'theta'
  37  );
  38  
  39  for ($real = -3.5; $real <= 3.5; $real += 0.5) {
  40      for ($imaginary = -3.5; $imaginary <= 3.5; $imaginary += 0.5) {
  41          foreach ($functions as $function) {
  42              $complexFunction = __NAMESPACE__ . '\\Functions::' . $function;
  43              $complex = new Complex($real, $imaginary);
  44              try {
  45                  echo $function, '(', $complex, ') = ', $complexFunction($complex), PHP_EOL;
  46              } catch (\Exception $e) {
  47                  echo $function, '(', $complex, ') ERROR: ', $e->getMessage(), PHP_EOL;
  48              }
  49          }
  50          echo PHP_EOL;
  51      }
  52  }