-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathComplex.cpp
71 lines (62 loc) · 959 Bytes
/
Complex.cpp
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
62
63
64
65
66
67
68
69
70
71
#include "common.h"
#include <mU/Number.h>
#include <mU/Complex.h>
#include <mU/System.h>
using namespace mU;
CPROC_INT(System_Complex, 2) {
Var v1 = At(x, 0);
Var v2 = At(x, 1);
if (NumQ(v1) && NumQ(v2))
{
return Complex(v1, v2);
}
else
{
return 0;
}
}
CPROC_INT(System_ComplexRe, 1) {
Var v = At(x, 0);
if (ObjQ(v, TAG(Complex)))
{
return Re(v);
}
else if (NumQ(v))
{
return v;
}
else
{
return 0;
}
}
CPROC_INT(System_ComplexIm, 1) {
Var v = At(x, 0);
if (ObjQ(v, TAG(Complex)))
{
return Im(v);
}
else if (NumQ(v))
{
return Int(static_cast<mU::uint>(0));
}
else
{
return 0;
}
}
CPROC_INT(System_ComplexConjugate, 1)
{
Var v = At(x, 0);
switch (Type(v))
{
case TYPE(int):
case TYPE(flt):
case TYPE(rat):
return v;
case TYPE(obj):
return ObjQ(v, TAG(Complex)) ? Complex(Re(v), N::Neg(Im(v))) : 0;
default:
return 0;
}
}