summaryrefslogtreecommitdiffstats
path: root/vendor/markbaker/complex/examples/testFunctions.php
blob: 69cc7dcfc6864947dfa0bf5de221305d0a0bc8bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

namespace Complex;

include('../classes/Bootstrap.php');

echo 'Function Examples', PHP_EOL;

$functions = array(
    'abs',
    'acos',
    'acosh',
    'acsc',
    'acsch',
    'argument',
    'asec',
    'asech',
    'asin',
    'asinh',
    'conjugate',
    'cos',
    'cosh',
    'csc',
    'csch',
    'exp',
    'inverse',
    'ln',
    'log2',
    'log10',
    'rho',
    'sec',
    'sech',
    'sin',
    'sinh',
    'sqrt',
    'theta'
);

for ($real = -3.5; $real <= 3.5; $real += 0.5) {
    for ($imaginary = -3.5; $imaginary <= 3.5; $imaginary += 0.5) {
        foreach ($functions as $function) {
            $complexFunction = __NAMESPACE__ . '\\' . $function;
            $complex = new Complex($real, $imaginary);
            try {
                echo $function, '(', $complex, ') = ', $complexFunction($complex), PHP_EOL;
            } catch (\Exception $e) {
                echo $function, '(', $complex, ') ERROR: ', $e->getMessage(), PHP_EOL;
            }
        }
        echo PHP_EOL;
    }
}