forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
complex.d.ts
238 lines (200 loc) · 6.19 KB
/
complex.d.ts
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// Type definitions for Complex 3.0.1
// Project: https://github.com/arian/Complex
// Definitions by: Aya Morisawa <https://github.com/AyaMorisawa>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module 'complex' {
export default class Complex {
/**
* @param real The real part of the number
* @param im The imaginary part of the number
*/
constructor(real: number, im: number);
/**
* A in line function like Number.from.
*
* Examples:
* var z = Complex.from(2, 4);
* var z = Complex.from(5);
* var z = Complex.from('2+5i');
*
* @param real A string representation of the number, for example 1+4i
*/
static from(real: string): Complex;
/**
* A in line function like Number.from.
* @param real The real part of the number
* @param im The imaginary part of the number
*/
static from(real: number, im?: number): Complex;
/**
* Creates a complex instance from a polar representation
* @param r The radius/magnitude of the number
* @param phi The angle/phase of the number
*/
static fromPolar(r: number, phi: number): Complex;
/**
* A instance of the imaginary unit
*/
static i: Complex;
/**
* A instance for the real number
*/
static one: Complex;
/**
* Set the real and imaginary properties a and b from a + bi.
* @param real The real part of the number
* @param im The imaginary part of the number
*/
fromRect(real: number, im: number): Complex;
/**
* Set the a and b in a + bi from a polar representation.
* @param r The radius/magnitude of the number
* @param phi The angle/phase of the number
*/
fromPolar(r: number, phi: number): Complex;
/**
* Set the precision of the numbers. Similar to Number.prototype.toPrecision. Useful before printing the number with the toString method.
* @param k An integer specifying the number of significant digits
*/
toPrecision(k: number): Complex;
/**
* Format a number using fixed-point notation. Similar to Number.prototype.toFixed. Useful before printing the number with the toString method.
* @param k The number of digits to appear after the decimal point; this may be a value between 0 and 20, inclusive, and implementations may optionally support a larger range of values. If this argument is omitted, it is treated as 0.
*/
toFixed(k: number): Complex;
/**
* Finalize the instance. The number will not change and any other method call will return a new instance. Very useful when a complex instance should stay constant. For example the Complex.i variable is a finalized instance.
*/
finalize(): Complex;
/**
* Calculate the magnitude of the complex number
*/
magnitude(): number;
/**
* Alias for magnitude(). Calculate the magnitude of the complex number.
*/
abs(): number;
/**
* Calculate the angle with respect to the real axis, in radians.
*/
angle(): number;
/**
* Alias for angle(). Calculate the angle with respect to the real axis, in radians.
*/
arg(): number;
/**
* Alias for angle(). Calculate the angle with respect to the real axis, in radians.
*/
phase(): number;
/**
* Calculate the conjugate of the complex number (multiplies the imaginary part with -1)
*/
conjugate(): Complex;
/**
* Negate the number (multiplies both the real and imaginary part with -1)
*/
negate(): Complex;
/**
* Multiply the number with a real or complex number
* @param z The number to multiply with
*/
multiply(z: number | Complex): Complex;
/**
* Alias for multiply(). Multiply the number with a real or complex number
* @param z The number to multiply with
*/
mult(z: number | Complex): Complex;
/**
* Divide the number by a real or complex number
* @param z The number to divide by
*/
divide(z: number | Complex): Complex;
/**
* Alias for divide(). Divide the number by a real or complex number
* @param z The number to divide by
*/
div(z: number | Complex): Complex;
/**
* Add a real or complex number
* @param z The number to add
*/
add(z: number | Complex): Complex;
/**
* Subtract a real or complex number
* @param z The number to subtract
*/
subtract(z: number | Complex): Complex;
/**
* Alias for subtract(). Subtract a real or complex number
* @param z The number to subtract
*/
sub(z: number | Complex): Complex;
/**
* Return the base to the exponent
* @param z The exponent
*/
pow(z: number | Complex): Complex;
/**
* Return the square root
*/
sqrt(): Complex;
/**
* Return the natural logarithm (base E)
* @param k The actual answer has a multiplicity (ln(z) = ln|z| + arg(z)) where arg(z) can return the same for different angles (every 2*pi), with this argument you can define which answer is required
*/
log(k?: number): Complex;
/**
* Calculate the e^z where the base is E and the exponential the complex number.
*/
exp(): Complex;
/**
* Calculate the sine of the complex number
*/
sin(): Complex;
/**
* Calculate the cosine of the complex number
*/
cos(): Complex;
/**
* Calculate the tangent of the complex number
*/
tan(): Complex;
/**
* Calculate the hyperbolic sine of the complex number
*/
sinh(): Complex
/**
* Calculate the hyperbolic cosine of the complex number
*/
cosh(): Complex
/**
* Calculate the hyperbolic tangent of the complex number
*/
tanh(): Complex
/**
* Return a new Complex instance with the same real and imaginary properties
*/
clone(): Complex;
/**
* Return a string representation of the complex number
*
* Examples:
* new Complex(1, 2).toString(); // 1+2i
* new Complex(0, 1).toString(); // i
* new Complex(4, 0).toString(); // 4
* new Complex(1, 1).toString(); // 1+i
* 'my Complex Number is: ' + (new Complex(3, 5)); // 'my Complex Number is: 3+5i
*/
toString(): string;
/**
* Check if the real and imaginary components are equal to the passed in compelex components.
*
* Examples:
* new Complex(1, 4).equals(new Complex(1, 4)); // true
* new Complex(1, 4).equals(new Complex(1, 3)); // false
*
* @param z The complex number to compare with
*/
equals(z: number | Complex): boolean;
}
}