-
Notifications
You must be signed in to change notification settings - Fork 0
/
complex.t
61 lines (38 loc) · 1.2 KB
/
complex.t
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
53
54
55
56
57
58
59
60
61
plan(24);
% sanity checks
1 + i;
ok(1, "1+i");
1.0 + i;
ok(1, "1.0+i");
2.0 + 10j;
ok(1, "2.0+10i");
20 + 5.5i;
ok(1, "20+5.5i");
31.5 - 20.7j;
ok(1, "20-20.7");
is(parrot_typeof(1 + 2i), "Complex", "check type with i is complex")
is(parrot_typeof(1 + 2j), "Complex", "check type with i is complex")
is(1 + 2i + 4 , 5+2i, "check add real part")
is(1+2i , 1+2i, "check identical")
is(1 + 2i + 4 +3j , 5+5i, "complex + complex")
is((1+2j)*(2+3j) , -4+7i, "check product")
is(sprintf("%s", 1+2i) , "1+2i", "sprintf 1")
is(sprintf("%s", 20+5.5i) , "20+5.5i", "sprintf 2")
nok(1+2i == 10, "check nothing crazy happens")
# i, j should behave like ordinary variables. although they default to sqrt(-1).
# see http://ccrma.stanford.edu/~jos/st/Complex_Numbers_Matlab_Octave.html
is(i , 0+1i, "i defaults to i")
is(j , 0+1j, "j defaults to j")
i = 100;
is(i , 100, "can overide i")
j = 101;
is(j , 101, "can override j")
# conj
is(conj(10+20i), 10-20i, "complex conj 1")
is(conj(1-2i), 1+2i, "complex conj 2")
is(conj(10), 10, "complex conj of non complex")
is(conj(5i), -5i, "complex conj imaginary")
is(conj(0), 0, "complex conj of 0")
A = [ 1+2i 2-3i; 10 0];
B = [ 1-2i 2+3i; 10 0];
is(conj(A), B, "array conj");