Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402]

   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  }