complexTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. use Complex\Complex as Complex;
  3. include(__DIR__ . '/../vendor/autoload.php');
  4. echo 'Create', PHP_EOL;
  5. $x = new Complex(123);
  6. echo $x, PHP_EOL;
  7. $x = new Complex(123, 456);
  8. echo $x, PHP_EOL;
  9. $x = new Complex(array(123,456,'j'));
  10. echo $x, PHP_EOL;
  11. $x = new Complex('1.23e-4--2.34e-5i');
  12. echo $x, PHP_EOL;
  13. echo PHP_EOL, 'Add', PHP_EOL;
  14. $x = new Complex(123);
  15. $x->add(456);
  16. echo $x, PHP_EOL;
  17. $x = new Complex(123.456);
  18. $x->add(789.012);
  19. echo $x, PHP_EOL;
  20. $x = new Complex(123.456, 78.90);
  21. $x->add(new Complex(-987.654, -32.1));
  22. echo $x, PHP_EOL;
  23. $x = new Complex(123.456, 78.90);
  24. $x->add(-987.654);
  25. echo $x, PHP_EOL;
  26. $x = new Complex(-987.654, -32.1);
  27. $x->add(new Complex(0, 1));
  28. echo $x, PHP_EOL;
  29. $x = new Complex(-987.654, -32.1);
  30. $x->add(new Complex(0, -1));
  31. echo $x, PHP_EOL;
  32. echo PHP_EOL, 'Subtract', PHP_EOL;
  33. $x = new Complex(123);
  34. $x->subtract(456);
  35. echo $x, PHP_EOL;
  36. $x = new Complex(123.456);
  37. $x->subtract(789.012);
  38. echo $x, PHP_EOL;
  39. $x = new Complex(123.456, 78.90);
  40. $x->subtract(new Complex(-987.654, -32.1));
  41. echo $x, PHP_EOL;
  42. $x = new Complex(123.456, 78.90);
  43. $x->subtract(-987.654);
  44. echo $x, PHP_EOL;
  45. $x = new Complex(-987.654, -32.1);
  46. $x->subtract(new Complex(0, 1));
  47. echo $x, PHP_EOL;
  48. $x = new Complex(-987.654, -32.1);
  49. $x->subtract(new Complex(0, -1));
  50. echo $x, PHP_EOL;
  51. echo PHP_EOL, 'Multiply', PHP_EOL;
  52. $x = new Complex(123);
  53. $x->multiply(456);
  54. echo $x, PHP_EOL;
  55. $x = new Complex(123.456);
  56. $x->multiply(789.012);
  57. echo $x, PHP_EOL;
  58. $x = new Complex(123.456, 78.90);
  59. $x->multiply(new Complex(-987.654, -32.1));
  60. echo $x, PHP_EOL;
  61. $x = new Complex(123.456, 78.90);
  62. $x->multiply(-987.654);
  63. echo $x, PHP_EOL;
  64. $x = new Complex(-987.654, -32.1);
  65. $x->multiply(new Complex(0, 1));
  66. echo $x, PHP_EOL;
  67. $x = new Complex(-987.654, -32.1);
  68. $x->multiply(new Complex(0, -1));
  69. echo $x, PHP_EOL;
  70. echo PHP_EOL, 'Divide By', PHP_EOL;
  71. $x = new Complex(123);
  72. $x->divideBy(456);
  73. echo $x, PHP_EOL;
  74. $x = new Complex(123.456);
  75. $x->divideBy(789.012);
  76. echo $x, PHP_EOL;
  77. $x = new Complex(123.456, 78.90);
  78. $x->divideBy(new Complex(-987.654, -32.1));
  79. echo $x, PHP_EOL;
  80. $x = new Complex(123.456, 78.90);
  81. $x->divideBy(-987.654);
  82. echo $x, PHP_EOL;
  83. $x = new Complex(-987.654, -32.1);
  84. $x->divideBy(new Complex(0, 1));
  85. echo $x, PHP_EOL;
  86. $x = new Complex(-987.654, -32.1);
  87. $x->divideBy(new Complex(0, -1));
  88. echo $x, PHP_EOL;
  89. echo PHP_EOL, 'Divide Into', PHP_EOL;
  90. $x = new Complex(123);
  91. $x->divideInto(456);
  92. echo $x, PHP_EOL;
  93. $x = new Complex(123.456);
  94. $x->divideInto(789.012);
  95. echo $x, PHP_EOL;
  96. $x = new Complex(123.456, 78.90);
  97. $x->divideInto(new Complex(-987.654, -32.1));
  98. echo $x, PHP_EOL;
  99. $x = new Complex(123.456, 78.90);
  100. $x->divideInto(-987.654);
  101. echo $x, PHP_EOL;
  102. $x = new Complex(-987.654, -32.1);
  103. $x->divideInto(new Complex(0, 1));
  104. echo $x, PHP_EOL;
  105. $x = new Complex(-987.654, -32.1);
  106. $x->divideInto(new Complex(0, -1));
  107. echo $x, PHP_EOL;