-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcomplexlib.h
148 lines (131 loc) · 4.73 KB
/
pcomplexlib.h
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifndef _PCOMPLEXLIB_H_
#define _PCOMPLEXLIB_H_
#include <iostream>
const int PRECISION = 2; // Used for round functions
using std::ostream;
using std::string;
class complex {
private:
double re, im;
bool isComplex;
void iscomplex(void);
public:
// ===== Constructors and destructor
complex(void);
complex(const double& r);
complex(const double& r, const double& i);
complex(const complex& z);
complex(const string& str);
~complex(void);
// ==== Erasing values
void reset(void);
friend void reset(complex& z);
// ===== Accessing private variables
double real(void);
friend double real(const complex& z);
double imag(void);
friend double imag(const complex& z);
friend bool iscomplex(const complex& z);
// ===== Complex special functions
complex conj(void);
friend complex conj(const complex& z);
double abs(void);
friend double abs(const complex& z);
double arg(void);
friend double arg(const complex& z);
double norm(void);
friend double norm(const complex& z);
// ===== Rounding complex numbers
complex round(const int& precision = PRECISION);
friend complex round(const complex& z, const int& precision = PRECISION);
// ===== Casting
operator const complex();
operator const string();
/*explicit operator const bool();
explicit operator const int();
explicit operator const float();*/ // no support in c++98
// ===== Assignment operators
void operator=(const complex& z);
void operator=(const double& d);
friend complex operator-(const complex& z); // -z
// ===== Addition operators
complex operator+(const complex& z);
complex operator+(const double& d);
friend complex operator+(const double& d, const complex& z);
void operator+=(const complex& z);
void operator+=(const double& d);
// ===== Subtraction operators
complex operator-(const complex& z);
complex operator-(const double& d);
friend complex operator-(const double& d, const complex& z);
void operator-=(const complex& z);
void operator-=(const double& d);
// ===== Multiplication operators
complex operator*(const complex& z);
complex operator*(const double& d);
friend complex operator*(const double& d, const complex& z);
void operator*=(const complex& z);
void operator*=(const double& d);
// ===== Division operators
complex operator/(const complex& z);
complex operator/(const double& d);
friend complex operator/(const double& d, const complex& z);
void operator/=(const complex& z);
void operator/=(const double& d);
// ===== Boolen operators
bool operator==(const complex& z);
bool operator!=(const complex& z);
bool operator<(const complex& z);
bool operator>(const complex& z);
bool operator<=(const complex& z);
bool operator>=(const complex& z);
// ===== Complex special operators
complex operator~(); // conjugate
friend double operator<(int, const complex& z); // argument
// ===== Input and output assignments
friend void getValue(complex& z);
friend ostream& operator<<(ostream& stream, const complex& z);
friend string to_string(const complex& z);
string to_string();
// ===== Logarithmic and exponential functions
friend complex log(const complex& z);
friend complex log2(const complex& z);
friend complex log10(const complex& z);
friend complex exp(const complex& z);
// ===== Power functions
complex pow(const double& d);
friend complex pow(const complex& z, const double& d);
friend complex pow(const double& d, const complex& c);
complex pow(const complex& c);
friend complex pow(const complex& z, const complex& c);
friend complex sqrt(const complex& z);
// ===== Trigonometric functions
friend complex sin(const complex& z);
friend complex cos(const complex& z);
friend complex tan(const complex& z);
friend complex csc(const complex& z);
friend complex sec(const complex& z);
friend complex cot(const complex& z);
// ===== Inverse trigonometric functions
friend complex asin(const complex& z);
friend complex acos(const complex& z);
friend complex atan(const complex& z);
friend complex acsc(const complex& z);
friend complex asec(const complex& z);
friend complex acot(const complex& z);
// ===== Hyperbolic functions
friend complex sinh(const complex& z);
friend complex cosh(const complex& z);
friend complex tanh(const complex& z);
friend complex csch(const complex& z);
friend complex sech(const complex& z);
friend complex coth(const complex& z);
// ===== Inverse hyperbolic functions
friend complex asinh(const complex& z);
friend complex acosh(const complex& z);
friend complex atanh(const complex& z);
friend complex acsch(const complex& z);
friend complex asech(const complex& z);
friend complex acoth(const complex& z);
};
#endif