Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   1  <?php
   2  
   3  use Complex\Complex as Complex;
   4  
   5  include ('../classes/Bootstrap.php');
   6  
   7  echo 'Create', PHP_EOL;
   8  
   9  $x = new Complex(123);
  10  echo $x, PHP_EOL;
  11  
  12  $x = new Complex(123, 456);
  13  echo $x, PHP_EOL;
  14  
  15  $x = new Complex(array(123,456,'j'));
  16  echo $x, PHP_EOL;
  17  
  18  $x = new Complex('1.23e-4--2.34e-5i');
  19  echo $x, PHP_EOL;
  20  
  21  
  22  echo PHP_EOL, 'Add', PHP_EOL;
  23  
  24  $x = new Complex(123);
  25  $x->add(456);
  26  echo $x, PHP_EOL;
  27  
  28  $x = new Complex(123.456);
  29  $x->add(789.012);
  30  echo $x, PHP_EOL;
  31  
  32  $x = new Complex(123.456, 78.90);
  33  $x->add(new Complex(-987.654, -32.1));
  34  echo $x, PHP_EOL;
  35  
  36  $x = new Complex(123.456, 78.90);
  37  $x->add(-987.654);
  38  echo $x, PHP_EOL;
  39  
  40  $x = new Complex(-987.654, -32.1);
  41  $x->add(new Complex(0, 1));
  42  echo $x, PHP_EOL;
  43  
  44  $x = new Complex(-987.654, -32.1);
  45  $x->add(new Complex(0, -1));
  46  echo $x, PHP_EOL;
  47  
  48  
  49  echo PHP_EOL, 'Subtract', PHP_EOL;
  50  
  51  $x = new Complex(123);
  52  $x->subtract(456);
  53  echo $x, PHP_EOL;
  54  
  55  $x = new Complex(123.456);
  56  $x->subtract(789.012);
  57  echo $x, PHP_EOL;
  58  
  59  $x = new Complex(123.456, 78.90);
  60  $x->subtract(new Complex(-987.654, -32.1));
  61  echo $x, PHP_EOL;
  62  
  63  $x = new Complex(123.456, 78.90);
  64  $x->subtract(-987.654);
  65  echo $x, PHP_EOL;
  66  
  67  $x = new Complex(-987.654, -32.1);
  68  $x->subtract(new Complex(0, 1));
  69  echo $x, PHP_EOL;
  70  
  71  $x = new Complex(-987.654, -32.1);
  72  $x->subtract(new Complex(0, -1));
  73  echo $x, PHP_EOL;
  74  
  75  
  76  echo PHP_EOL, 'Multiply', PHP_EOL;
  77  
  78  $x = new Complex(123);
  79  $x->multiply(456);
  80  echo $x, PHP_EOL;
  81  
  82  $x = new Complex(123.456);
  83  $x->multiply(789.012);
  84  echo $x, PHP_EOL;
  85  
  86  $x = new Complex(123.456, 78.90);
  87  $x->multiply(new Complex(-987.654, -32.1));
  88  echo $x, PHP_EOL;
  89  
  90  $x = new Complex(123.456, 78.90);
  91  $x->multiply(-987.654);
  92  echo $x, PHP_EOL;
  93  
  94  $x = new Complex(-987.654, -32.1);
  95  $x->multiply(new Complex(0, 1));
  96  echo $x, PHP_EOL;
  97  
  98  $x = new Complex(-987.654, -32.1);
  99  $x->multiply(new Complex(0, -1));
 100  echo $x, PHP_EOL;
 101  
 102  
 103  echo PHP_EOL, 'Divide By', PHP_EOL;
 104  
 105  $x = new Complex(123);
 106  $x->divideBy(456);
 107  echo $x, PHP_EOL;
 108  
 109  $x = new Complex(123.456);
 110  $x->divideBy(789.012);
 111  echo $x, PHP_EOL;
 112  
 113  $x = new Complex(123.456, 78.90);
 114  $x->divideBy(new Complex(-987.654, -32.1));
 115  echo $x, PHP_EOL;
 116  
 117  $x = new Complex(123.456, 78.90);
 118  $x->divideBy(-987.654);
 119  echo $x, PHP_EOL;
 120  
 121  $x = new Complex(-987.654, -32.1);
 122  $x->divideBy(new Complex(0, 1));
 123  echo $x, PHP_EOL;
 124  
 125  $x = new Complex(-987.654, -32.1);
 126  $x->divideBy(new Complex(0, -1));
 127  echo $x, PHP_EOL;
 128  
 129  
 130  echo PHP_EOL, 'Divide Into', PHP_EOL;
 131  
 132  $x = new Complex(123);
 133  $x->divideInto(456);
 134  echo $x, PHP_EOL;
 135  
 136  $x = new Complex(123.456);
 137  $x->divideInto(789.012);
 138  echo $x, PHP_EOL;
 139  
 140  $x = new Complex(123.456, 78.90);
 141  $x->divideInto(new Complex(-987.654, -32.1));
 142  echo $x, PHP_EOL;
 143  
 144  $x = new Complex(123.456, 78.90);
 145  $x->divideInto(-987.654);
 146  echo $x, PHP_EOL;
 147  
 148  $x = new Complex(-987.654, -32.1);
 149  $x->divideInto(new Complex(0, 1));
 150  echo $x, PHP_EOL;
 151  
 152  $x = new Complex(-987.654, -32.1);
 153  $x->divideInto(new Complex(0, -1));
 154  echo $x, PHP_EOL;