v2 / vlib / math / complex / complex_test.v
784 lines · 740 sloc · 27.71 KB · e07eb549e4a6a1c827bccafdc69d66e66490c7d7
Raw
1import math
2import math.complex as cmplx
3
4fn tst_res(str1 string, str2 string) bool {
5 if (math.abs(str1.f64() - str2.f64())) < 1e-5 {
6 return true
7 }
8 return false
9}
10
11fn test_complex_addition() {
12 // Test is based on and verified from practice examples of Khan Academy
13 // https://www.khanacademy.org/math/precalculus/imaginary-and-complex-numbers
14 mut c1 := cmplx.complex(0, -10)
15 mut c2 := cmplx.complex(-40, 8)
16 mut result := c1 + c2
17 assert result.equals(cmplx.complex(-40, -2))
18 c1 = cmplx.complex(-71, 2)
19 c2 = cmplx.complex(88, -12)
20 result = c1 + c2
21 assert result.equals(cmplx.complex(17, -10))
22 c1 = cmplx.complex(0, -30)
23 c2 = cmplx.complex(52, -30)
24 result = c1 + c2
25 assert result.equals(cmplx.complex(52, -60))
26 c1 = cmplx.complex(12, -9)
27 c2 = cmplx.complex(32, -6)
28 result = c1 + c2
29 assert result.equals(cmplx.complex(44, -15))
30}
31
32fn test_complex_subtraction() {
33 // Test is based on and verified from practice examples of Khan Academy
34 // https://www.khanacademy.org/math/precalculus/imaginary-and-complex-numbers
35 mut c1 := cmplx.complex(-8, 0)
36 mut c2 := cmplx.complex(6, 30)
37 mut result := c1 - c2
38 assert result.equals(cmplx.complex(-14, -30))
39 c1 = cmplx.complex(-19, 7)
40 c2 = cmplx.complex(29, 32)
41 result = c1 - c2
42 assert result.equals(cmplx.complex(-48, -25))
43 c1 = cmplx.complex(12, 0)
44 c2 = cmplx.complex(23, 13)
45 result = c1 - c2
46 assert result.equals(cmplx.complex(-11, -13))
47 c1 = cmplx.complex(-14, 3)
48 c2 = cmplx.complex(0, 14)
49 result = c1 - c2
50 assert result.equals(cmplx.complex(-14, -11))
51}
52
53fn test_complex_multiplication() {
54 // Test is based on and verified from practice examples of Khan Academy
55 // https://www.khanacademy.org/math/precalculus/imaginary-and-complex-numbers
56 mut c1 := cmplx.complex(1, 2)
57 mut c2 := cmplx.complex(1, -4)
58 mut result := c1 * c2
59 assert result.equals(cmplx.complex(9, -2))
60 c1 = cmplx.complex(-4, -4)
61 c2 = cmplx.complex(-5, -3)
62 result = c1 * c2
63 assert result.equals(cmplx.complex(8, 32))
64 c1 = cmplx.complex(4, 4)
65 c2 = cmplx.complex(-2, -5)
66 result = c1 * c2
67 assert result.equals(cmplx.complex(12, -28))
68 c1 = cmplx.complex(2, -2)
69 c2 = cmplx.complex(4, -4)
70 result = c1 * c2
71 assert result.equals(cmplx.complex(0, -16))
72}
73
74fn test_complex_division() {
75 // Test is based on and verified from practice examples of Khan Academy
76 // https://www.khanacademy.org/math/precalculus/imaginary-and-complex-numbers
77 mut c1 := cmplx.complex(-9, -6)
78 mut c2 := cmplx.complex(-3, -2)
79 mut result := c1 / c2
80 assert result.equals(cmplx.complex(3, 0))
81 c1 = cmplx.complex(-23, 11)
82 c2 = cmplx.complex(5, 1)
83 result = c1 / c2
84 assert result.equals(cmplx.complex(-4, 3))
85 c1 = cmplx.complex(8, -2)
86 c2 = cmplx.complex(-4, 1)
87 result = c1 / c2
88 assert result.equals(cmplx.complex(-2, 0))
89 c1 = cmplx.complex(11, 24)
90 c2 = cmplx.complex(-4, -1)
91 result = c1 / c2
92 assert result.equals(cmplx.complex(-4, -5))
93}
94
95fn test_complex_conjugate() {
96 // Test is based on and verified from practice examples of Khan Academy
97 // https://www.khanacademy.org/math/precalculus/imaginary-and-complex-numbers
98 mut c1 := cmplx.complex(0, 8)
99 mut result := c1.conjugate()
100 assert result.equals(cmplx.complex(0, -8))
101 c1 = cmplx.complex(7, 3)
102 result = c1.conjugate()
103 assert result.equals(cmplx.complex(7, -3))
104 c1 = cmplx.complex(2, 2)
105 result = c1.conjugate()
106 assert result.equals(cmplx.complex(2, -2))
107 c1 = cmplx.complex(7, 0)
108 result = c1.conjugate()
109 assert result.equals(cmplx.complex(7, 0))
110}
111
112fn test_complex_equals() {
113 mut c1 := cmplx.complex(0, 8)
114 mut c2 := cmplx.complex(0, 8)
115 assert c1.equals(c2)
116 c1 = cmplx.complex(-3, 19)
117 c2 = cmplx.complex(-3, 19)
118 assert c1.equals(c2)
119}
120
121fn test_complex_abs() {
122 mut c1 := cmplx.complex(3, 4)
123 assert c1.abs() == 5
124 c1 = cmplx.complex(1, 2)
125 assert c1.abs() == math.sqrt(5)
126 assert c1.abs() == c1.conjugate().abs()
127 c1 = cmplx.complex(7, 0)
128 assert c1.abs() == 7
129}
130
131fn test_complex_angle() {
132 // Test is based on and verified from practice examples of Khan Academy
133 // https://www.khanacademy.org/math/precalculus/imaginary-and-complex-numbers
134 mut c := cmplx.complex(1, 0)
135 assert c.angle() * 180 / math.pi == 0
136 c = cmplx.complex(1, 1)
137 assert c.angle() * 180 / math.pi == 45
138 c = cmplx.complex(0, 1)
139 assert c.angle() * 180 / math.pi == 90
140 c = cmplx.complex(-1, 1)
141 assert c.angle() * 180 / math.pi == 135
142 c = cmplx.complex(-1, -1)
143 assert c.angle() * 180 / math.pi == -135
144 cc := c.conjugate()
145 a := cc.angle()
146 assert a + c.angle() == 0
147}
148
149fn test_complex_addinv() {
150 // Tests were also verified on Wolfram Alpha
151 mut c1 := cmplx.complex(5, 7)
152 mut c2 := cmplx.complex(-5, -7)
153 mut result := c1.addinv()
154 assert result.equals(c2)
155 c1 = cmplx.complex(-3, 4)
156 c2 = cmplx.complex(3, -4)
157 result = c1.addinv()
158 assert result.equals(c2)
159 c1 = cmplx.complex(-1, -2)
160 c2 = cmplx.complex(1, 2)
161 result = c1.addinv()
162 assert result.equals(c2)
163}
164
165fn test_complex_mulinv() {
166 // Tests were also verified on Wolfram Alpha
167 mut c1 := cmplx.complex(5, 7)
168 mut c2 := cmplx.complex(0.067568, -0.094595)
169 mut result := c1.mulinv()
170 // Some issue with precision comparison in f64 using == operator hence serializing to string
171 println(c2.str())
172 println(result.str())
173 assert result.str() == c2.str()
174 c1 = cmplx.complex(-3, 4)
175 c2 = cmplx.complex(-0.12, -0.16)
176 result = c1.mulinv()
177 assert result.str() == c2.str()
178 c1 = cmplx.complex(-1, -2)
179 c2 = cmplx.complex(-0.2, 0.4)
180 result = c1.mulinv()
181 assert result.equals(c2)
182}
183
184fn test_complex_mod() {
185 // Tests were also verified on Wolfram Alpha
186 mut c1 := cmplx.complex(5, 7)
187 mut result := c1.mod()
188 // Some issue with precision comparison in f64 using == operator hence serializing to string
189 assert tst_res(result.str(), '8.602325')
190 c1 = cmplx.complex(-3, 4)
191 result = c1.mod()
192 assert result == 5
193 c1 = cmplx.complex(-1, -2)
194 result = c1.mod()
195 // Some issue with precision comparison in f64 using == operator hence serializing to string
196 assert tst_res(result.str(), '2.236068')
197}
198
199fn test_complex_pow() {
200 // Tests were also verified on Wolfram Alpha
201 mut c1 := cmplx.complex(5, 7)
202 mut c2 := cmplx.complex(-24.0, 70.0)
203 mut result := c1.pow(2)
204 // Some issue with precision comparison in f64 using == operator hence serializing to string
205 assert result.str() == c2.str()
206 c1 = cmplx.complex(-3, 4)
207 c2 = cmplx.complex(117, 44)
208 result = c1.pow(3)
209 // Some issue with precision comparison in f64 using == operator hence serializing to string
210 assert result.str() == c2.str()
211 c1 = cmplx.complex(-1, -2)
212 c2 = cmplx.complex(-7, -24)
213 result = c1.pow(4)
214 // Some issue with precision comparison in f64 using == operator hence serializing to string
215 assert result.str() == c2.str()
216}
217
218fn test_complex_root() {
219 // Tests were also verified on Wolfram Alpha
220 mut c1 := cmplx.complex(5, 7)
221 mut c2 := cmplx.complex(2.607904, 1.342074)
222 mut result := c1.root(2)
223 // Some issue with precision comparison in f64 using == operator hence serializing to string
224 assert result.str() == c2.str()
225 c1 = cmplx.complex(-3, 4)
226 c2 = cmplx.complex(1.264953, 1.150614)
227 result = c1.root(3)
228 // Some issue with precision comparison in f64 using == operator hence serializing to string
229 assert result.str() == c2.str()
230 c1 = cmplx.complex(-1, -2)
231 c2 = cmplx.complex(1.068059, -0.595482)
232 result = c1.root(4)
233 // Some issue with precision comparison in f64 using == operator hence serializing to string
234 assert result.str() == c2.str()
235}
236
237fn test_complex_exp() {
238 // Tests were also verified on Wolfram Alpha
239 mut c1 := cmplx.complex(5, 7)
240 mut c2 := cmplx.complex(111.889015, 97.505457)
241 mut result := c1.exp()
242 // Some issue with precision comparison in f64 using == operator hence serializing to string
243 assert result.str() == c2.str()
244 c1 = cmplx.complex(-3, 4)
245 c2 = cmplx.complex(-0.032543, -0.037679)
246 result = c1.exp()
247 // Some issue with precision comparison in f64 using == operator hence serializing to string
248 assert result.str() == c2.str()
249 c1 = cmplx.complex(-1, -2)
250 c2 = cmplx.complex(-0.153092, -0.334512)
251 result = c1.exp()
252 // Some issue with precision comparison in f64 using == operator hence serializing to string
253 assert result.str() == c2.str()
254}
255
256fn test_complex_ln() {
257 // Tests were also verified on Wolfram Alpha
258 mut c1 := cmplx.complex(5, 7)
259 mut c2 := cmplx.complex(2.152033, 0.950547)
260 mut result := c1.ln()
261 // Some issue with precision comparison in f64 using == operator hence serializing to string
262 assert result.str() == c2.str()
263 c1 = cmplx.complex(-3, 4)
264 c2 = cmplx.complex(1.609438, 2.214297)
265 result = c1.ln()
266 // Some issue with precision comparison in f64 using == operator hence serializing to string
267 assert result.str() == c2.str()
268 c1 = cmplx.complex(-1, -2)
269 c2 = cmplx.complex(0.804719, -2.034444)
270 result = c1.ln()
271 // Some issue with precision comparison in f64 using == operator hence serializing to string
272 assert result.str() == c2.str()
273}
274
275fn test_complex_arg() {
276 // Tests were also verified on Wolfram Alpha
277 mut c1 := cmplx.complex(5, 7)
278 mut c2 := cmplx.complex(2.152033, 0.950547)
279 mut result := c1.arg()
280 // Some issue with precision comparison in f64 using == operator hence serializing to string
281 assert tst_res(result.str(), '0.950547')
282 c1 = cmplx.complex(-3, 4)
283 c2 = cmplx.complex(1.609438, 2.214297)
284 result = c1.arg()
285 // Some issue with precision comparison in f64 using == operator hence serializing to string
286 assert tst_res(result.str(), '2.214297')
287 c1 = cmplx.complex(-1, -2)
288 c2 = cmplx.complex(0.804719, -2.034444)
289 result = c1.arg()
290 // Some issue with precision comparison in f64 using == operator hence serializing to string
291 assert tst_res(result.str(), '-2.034444')
292}
293
294fn test_complex_log() {
295 a := cmplx.complex(11.22, 33.44)
296 b := cmplx.complex(55.66, 77.88)
297 c := a.log(b)
298 assert c.re.eq_epsilon(0.8032210844549097)
299 assert c.im.eq_epsilon(0.10605953671930149)
300}
301
302fn test_complex_cpow() {
303 // Tests were also verified on Wolfram Alpha
304 mut c1 := cmplx.complex(5, 7)
305 mut r1 := cmplx.complex(2, 2)
306 mut c2 := cmplx.complex(11.022341, -0.861785)
307 mut result := c1.cpow(r1)
308 // Some issue with precision comparison in f64 using == operator hence serializing to string
309 assert result.str() == c2.str()
310 c1 = cmplx.complex(-3, 4)
311 r1 = cmplx.complex(-4, -2)
312 c2 = cmplx.complex(0.118303, 0.063148)
313 result = c1.cpow(r1)
314 // Some issue with precision comparison in f64 using == operator hence serializing to string
315 assert result.str() == c2.str()
316 c1 = cmplx.complex(-1, -2)
317 r1 = cmplx.complex(8, -9)
318 c2 = cmplx.complex(-0.000000, 0.000007)
319 result = c1.cpow(r1)
320 // Some issue with precision comparison in f64 using == operator hence serializing to string
321 assert result.str() == c2.str()
322}
323
324fn test_complex_sin() {
325 // Tests were also verified on Wolfram Alpha
326 mut c1 := cmplx.complex(5, 7)
327 mut c2 := cmplx.complex(-525.794515, 155.536550)
328 mut result := c1.sin()
329 // Some issue with precision comparison in f64 using == operator hence serializing to string
330 assert result.str() == c2.str()
331 c1 = cmplx.complex(-3, 4)
332 c2 = cmplx.complex(-3.853738, -27.016813)
333 result = c1.sin()
334 // Some issue with precision comparison in f64 using == operator hence serializing to string
335 assert result.str() == c2.str()
336 c1 = cmplx.complex(-1, -2)
337 c2 = cmplx.complex(-3.165779, -1.959601)
338 result = c1.sin()
339 // Some issue with precision comparison in f64 using == operator hence serializing to string
340 assert result.str() == c2.str()
341}
342
343fn test_complex_cos() {
344 // Tests were also verified on Wolfram Alpha
345 mut c1 := cmplx.complex(5, 7)
346 mut c2 := cmplx.complex(155.536809, 525.793641)
347 mut result := c1.cos()
348 // Some issue with precision comparison in f64 using == operator hence serializing to string
349 assert result.str() == c2.str()
350 c1 = cmplx.complex(-3, 4)
351 c2 = cmplx.complex(-27.034946, 3.851153)
352 result = c1.cos()
353 // Some issue with precision comparison in f64 using == operator hence serializing to string
354 assert result.str() == c2.str()
355 c1 = cmplx.complex(-1, -2)
356 c2 = cmplx.complex(2.032723, -3.051898)
357 result = c1.cos()
358 // Some issue with precision comparison in f64 using == operator hence serializing to string
359 assert result.str() == c2.str()
360}
361
362fn test_complex_tan() {
363 // Tests were also verified on Wolfram Alpha
364 mut c1 := cmplx.complex(5, 7)
365 mut c2 := cmplx.complex(-0.000001, 1.000001)
366 mut result := c1.tan()
367 // Some issue with precision comparison in f64 using == operator hence serializing to string
368 assert result.str() == c2.str()
369 c1 = cmplx.complex(-3, 4)
370 c2 = cmplx.complex(0.000187, 0.999356)
371 result = c1.tan()
372 // Some issue with precision comparison in f64 using == operator hence serializing to string
373 assert result.str() == c2.str()
374 c1 = cmplx.complex(-1, -2)
375 c2 = cmplx.complex(-0.033813, -1.014794)
376 result = c1.tan()
377 // Some issue with precision comparison in f64 using == operator hence serializing to string
378 assert result.str() == c2.str()
379}
380
381fn test_complex_cot() {
382 // Tests were also verified on Wolfram Alpha
383 mut c1 := cmplx.complex(5, 7)
384 mut c2 := cmplx.complex(-0.000001, -0.999999)
385 mut result := c1.cot()
386 // Some issue with precision comparison in f64 using == operator hence serializing to string
387 assert result.str() == c2.str()
388 c1 = cmplx.complex(-3, 4)
389 c2 = cmplx.complex(0.000188, -1.000644)
390 result = c1.cot()
391 // Some issue with precision comparison in f64 using == operator hence serializing to string
392 assert result.str() == c2.str()
393 c1 = cmplx.complex(-1, -2)
394 c2 = cmplx.complex(-0.032798, 0.984329)
395 result = c1.cot()
396 // Some issue with precision comparison in f64 using == operator hence serializing to string
397 assert result.str() == c2.str()
398}
399
400fn test_complex_sec() {
401 // Tests were also verified on Wolfram Alpha
402 mut c1 := cmplx.complex(5, 7)
403 mut c2 := cmplx.complex(0.000517, -0.001749)
404 mut result := c1.sec()
405 // Some issue with precision comparison in f64 using == operator hence serializing to string
406 assert result.str() == c2.str()
407 c1 = cmplx.complex(-3, 4)
408 c2 = cmplx.complex(-0.036253, -0.005164)
409 result = c1.sec()
410 // Some issue with precision comparison in f64 using == operator hence serializing to string
411 assert result.str() == c2.str()
412 c1 = cmplx.complex(-1, -2)
413 c2 = cmplx.complex(0.151176, 0.226974)
414 result = c1.sec()
415 // Some issue with precision comparison in f64 using == operator hence serializing to string
416 assert result.str() == c2.str()
417}
418
419fn test_complex_csc() {
420 // Tests were also verified on Wolfram Alpha
421 mut c1 := cmplx.complex(5, 7)
422 mut c2 := cmplx.complex(-0.001749, -0.000517)
423 mut result := c1.csc()
424 // Some issue with precision comparison in f64 using == operator hence serializing to string
425 assert result.str() == c2.str()
426 c1 = cmplx.complex(-3, 4)
427 c2 = cmplx.complex(-0.005174, 0.036276)
428 result = c1.csc()
429 // Some issue with precision comparison in f64 using == operator hence serializing to string
430 assert result.str() == c2.str()
431 c1 = cmplx.complex(-1, -2)
432 c2 = cmplx.complex(-0.228375, 0.141363)
433 result = c1.csc()
434 // Some issue with precision comparison in f64 using == operator hence serializing to string
435 assert result.str() == c2.str()
436}
437
438fn test_complex_asin() {
439 // Tests were also verified on Wolfram Alpha
440 mut c1 := cmplx.complex(5, 7)
441 mut c2 := cmplx.complex(0.617064, 2.846289)
442 mut result := c1.asin()
443 // Some issue with precision comparison in f64 using == operator hence serializing to string
444 assert result.str() == c2.str()
445 c1 = cmplx.complex(-3, 4)
446 c2 = cmplx.complex(-0.633984, 2.305509)
447 result = c1.asin()
448 // Some issue with precision comparison in f64 using == operator hence serializing to string
449 assert result.str() == c2.str()
450 c1 = cmplx.complex(-1, -2)
451 c2 = cmplx.complex(-0.427079, -1.528571)
452 result = c1.asin()
453 // Some issue with precision comparison in f64 using == operator hence serializing to string
454 assert result.str() == c2.str()
455}
456
457fn test_complex_acos() {
458 // Tests were also verified on Wolfram Alpha
459 mut c1 := cmplx.complex(5, 7)
460 mut c2 := cmplx.complex(0.953732, -2.846289)
461 mut result := c1.acos()
462 // Some issue with precision comparison in f64 using == operator hence serializing to string
463 assert result.str() == c2.str()
464 c1 = cmplx.complex(-3, 4)
465 c2 = cmplx.complex(2.204780, -2.305509)
466 result = c1.acos()
467 // Some issue with precision comparison in f64 using == operator hence serializing to string
468 assert result.str() == c2.str()
469 c1 = cmplx.complex(-1, -2)
470 c2 = cmplx.complex(1.997875, 1.528571)
471 result = c1.acos()
472 // Some issue with precision comparison in f64 using == operator hence serializing to string
473 assert result.str() == c2.str()
474}
475
476fn test_complex_atan() {
477 // Tests were also verified on Wolfram Alpha
478 mut c1 := cmplx.complex(5, 7)
479 mut c2 := cmplx.complex(1.502727, 0.094441)
480 mut result := c1.atan()
481 // Some issue with precision comparison in f64 using == operator hence serializing to string
482 assert result.str() == c2.str()
483 c1 = cmplx.complex(-3, 4)
484 c2 = cmplx.complex(-1.448307, 0.158997)
485 result = c1.atan()
486 // Some issue with precision comparison in f64 using == operator hence serializing to string
487 assert result.str() == c2.str()
488 c1 = cmplx.complex(-1, -2)
489 c2 = cmplx.complex(-1.338973, -0.402359)
490 result = c1.atan()
491 // Some issue with precision comparison in f64 using == operator hence serializing to string
492 assert result.str() == c2.str()
493}
494
495fn test_complex_acot() {
496 // Tests were also verified on Wolfram Alpha
497 mut c1 := cmplx.complex(5, 7)
498 mut c2 := cmplx.complex(0.068069, -0.094441)
499 mut result := c1.acot()
500 // Some issue with precision comparison in f64 using == operator hence serializing to string
501 assert result.str() == c2.str()
502 c1 = cmplx.complex(-3, 4)
503 c2 = cmplx.complex(-0.122489, -0.158997)
504 result = c1.acot()
505 // Some issue with precision comparison in f64 using == operator hence serializing to string
506 assert result.str() == c2.str()
507 c1 = cmplx.complex(-1, -2)
508 c2 = cmplx.complex(-0.231824, 0.402359)
509 result = c1.acot()
510 // Some issue with precision comparison in f64 using == operator hence serializing to string
511 assert result.str() == c2.str()
512}
513
514fn test_complex_asec() {
515 // Tests were also verified on Wolfram Alpha
516 mut c1 := cmplx.complex(5, 7)
517 mut c2 := cmplx.complex(1.503480, 0.094668)
518 mut result := c1.asec()
519 // Some issue with precision comparison in f64 using == operator hence serializing to string
520 assert result.str() == c2.str()
521 c1 = cmplx.complex(-3, 4)
522 c2 = cmplx.complex(1.689547, 0.160446)
523 result = c1.asec()
524 // Some issue with precision comparison in f64 using == operator hence serializing to string
525 assert result.str() == c2.str()
526 c1 = cmplx.complex(-1, -2)
527 c2 = cmplx.complex(1.757114, -0.396568)
528 result = c1.asec()
529 // Some issue with precision comparison in f64 using == operator hence serializing to string
530 assert result.str() == c2.str()
531}
532
533fn test_complex_acsc() {
534 // Tests were also verified on Wolfram Alpha
535 mut c1 := cmplx.complex(5, 7)
536 mut c2 := cmplx.complex(0.067317, -0.094668)
537 mut result := c1.acsc()
538 // Some issue with precision comparison in f64 using == operator hence serializing to string
539 assert result.str() == c2.str()
540 c1 = cmplx.complex(-3, 4)
541 c2 = cmplx.complex(-0.118751, -0.160446)
542 result = c1.acsc()
543 // Some issue with precision comparison in f64 using == operator hence serializing to string
544 assert result.str() == c2.str()
545 c1 = cmplx.complex(-1, -2)
546 c2 = cmplx.complex(-0.186318, 0.396568)
547 result = c1.acsc()
548 // Some issue with precision comparison in f64 using == operator hence serializing to string
549 assert result.str() == c2.str()
550}
551
552fn test_complex_sinh() {
553 // Tests were also verified on Wolfram Alpha
554 mut c1 := cmplx.complex(5, 7)
555 mut c2 := cmplx.complex(55.941968, 48.754942)
556 mut result := c1.sinh()
557 // Some issue with precision comparison in f64 using == operator hence serializing to string
558 assert result.str() == c2.str()
559 c1 = cmplx.complex(-3, 4)
560 c2 = cmplx.complex(6.548120, -7.619232)
561 result = c1.sinh()
562 // Some issue with precision comparison in f64 using == operator hence serializing to string
563 assert result.str() == c2.str()
564 c1 = cmplx.complex(-1, -2)
565 c2 = cmplx.complex(0.489056, -1.403119)
566 result = c1.sinh()
567 // Some issue with precision comparison in f64 using == operator hence serializing to string
568 assert result.str() == c2.str()
569}
570
571fn test_complex_cosh() {
572 // Tests were also verified on Wolfram Alpha
573 mut c1 := cmplx.complex(5, 7)
574 mut c2 := cmplx.complex(55.947047, 48.750515)
575 mut result := c1.cosh()
576 // Some issue with precision comparison in f64 using == operator hence serializing to string
577 assert result.str() == c2.str()
578 c1 = cmplx.complex(-3, 4)
579 c2 = cmplx.complex(-6.580663, 7.581553)
580 result = c1.cosh()
581 // Some issue with precision comparison in f64 using == operator hence serializing to string
582 assert result.str() == c2.str()
583 c1 = cmplx.complex(-1, -2)
584 c2 = cmplx.complex(-0.642148, 1.068607)
585 result = c1.cosh()
586 // Some issue with precision comparison in f64 using == operator hence serializing to string
587 assert result.str() == c2.str()
588}
589
590fn test_complex_tanh() {
591 // Tests were also verified on Wolfram Alpha
592 mut c1 := cmplx.complex(5, 7)
593 mut c2 := cmplx.complex(0.999988, 0.000090)
594 mut result := c1.tanh()
595 // Some issue with precision comparison in f64 using == operator hence serializing to string
596 assert result.str() == c2.str()
597 c1 = cmplx.complex(-3, 4)
598 c2 = cmplx.complex(-1.000710, 0.004908)
599 result = c1.tanh()
600 // Some issue with precision comparison in f64 using == operator hence serializing to string
601 assert result.str() == c2.str()
602 c1 = cmplx.complex(-1, -2)
603 c2 = cmplx.complex(-1.166736, 0.243458)
604 result = c1.tanh()
605 // Some issue with precision comparison in f64 using == operator hence serializing to string
606 assert result.str() == c2.str()
607}
608
609fn test_complex_coth() {
610 // Tests were also verified on Wolfram Alpha
611 mut c1 := cmplx.complex(5, 7)
612 mut c2 := cmplx.complex(1.000012, -0.000090)
613 mut result := c1.coth()
614 // Some issue with precision comparison in f64 using == operator hence serializing to string
615 assert result.str() == c2.str()
616 c1 = cmplx.complex(-3, 4)
617 c2 = cmplx.complex(-0.999267, -0.004901)
618 result = c1.coth()
619 // Some issue with precision comparison in f64 using == operator hence serializing to string
620 assert result.str() == c2.str()
621 c1 = cmplx.complex(-1, -2)
622 c2 = cmplx.complex(-0.821330, -0.171384)
623 result = c1.coth()
624 // Some issue with precision comparison in f64 using == operator hence serializing to string
625 assert result.str() == c2.str()
626}
627
628fn test_complex_sech() {
629 // Tests were also verified on Wolfram Alpha
630 mut c1 := cmplx.complex(5, 7)
631 mut c2 := cmplx.complex(0.010160, -0.008853)
632 mut result := c1.sech()
633 // Some issue with precision comparison in f64 using == operator hence serializing to string
634 assert result.str() == c2.str()
635 c1 = cmplx.complex(-3, 4)
636 c2 = cmplx.complex(-0.065294, -0.075225)
637 result = c1.sech()
638 // Some issue with precision comparison in f64 using == operator hence serializing to string
639 assert result.str() == c2.str()
640 c1 = cmplx.complex(-1, -2)
641 c2 = cmplx.complex(-0.413149, -0.687527)
642 result = c1.sech()
643 // Some issue with precision comparison in f64 using == operator hence serializing to string
644 assert result.str() == c2.str()
645}
646
647fn test_complex_csch() {
648 // Tests were also verified on Wolfram Alpha
649 mut c1 := cmplx.complex(5, 7)
650 mut c2 := cmplx.complex(0.010159, -0.008854)
651 mut result := c1.csch()
652 // Some issue with precision comparison in f64 using == operator hence serializing to string
653 assert result.str() == c2.str()
654 c1 = cmplx.complex(-3, 4)
655 c2 = cmplx.complex(0.064877, 0.075490)
656 result = c1.csch()
657 // Some issue with precision comparison in f64 using == operator hence serializing to string
658 assert result.str() == c2.str()
659 c1 = cmplx.complex(-1, -2)
660 c2 = cmplx.complex(0.221501, 0.635494)
661 result = c1.csch()
662 // Some issue with precision comparison in f64 using == operator hence serializing to string
663 assert result.str() == c2.str()
664}
665
666fn test_complex_asinh() {
667 // Tests were also verified on Wolfram Alpha
668 mut c1 := cmplx.complex(5, 7)
669 mut c2 := cmplx.complex(2.844098, 0.947341)
670 mut result := c1.asinh()
671 // Some issue with precision comparison in f64 using == operator hence serializing to string
672 assert result.str() == c2.str()
673 c1 = cmplx.complex(-3, 4)
674 c2 = cmplx.complex(-2.299914, 0.917617)
675 result = c1.asinh()
676 // Some issue with precision comparison in f64 using == operator hence serializing to string
677 assert result.str() == c2.str()
678 c1 = cmplx.complex(-1, -2)
679 c2 = cmplx.complex(-1.469352, -1.063440)
680 result = c1.asinh()
681 // Some issue with precision comparison in f64 using == operator hence serializing to string
682 assert result.str() == c2.str()
683}
684
685fn test_complex_acosh() {
686 // Tests were also verified on Wolfram Alpha
687 mut c1 := cmplx.complex(5, 7)
688 mut c2 := cmplx.complex(2.846289, 0.953732)
689 mut result := c1.acosh()
690 // Some issue with precision comparison in f64 using == operator hence serializing to string
691 assert result.str() == c2.str()
692 c1 = cmplx.complex(-3, 4)
693 c2 = cmplx.complex(2.305509, 2.204780)
694 result = c1.acosh()
695 // Some issue with precision comparison in f64 using == operator hence serializing to string
696 assert result.str() == c2.str()
697 c1 = cmplx.complex(-1, -2)
698 c2 = cmplx.complex(1.528571, -1.997875)
699 result = c1.acosh()
700 // Some issue with precision comparison in f64 using == operator hence serializing to string
701 assert result.str() == c2.str()
702}
703
704fn test_complex_atanh() {
705 // Tests were also verified on Wolfram Alpha
706 mut c1 := cmplx.complex(5, 7)
707 mut c2 := cmplx.complex(0.067066, 1.476056)
708 mut result := c1.atanh()
709 // Some issue with precision comparison in f64 using == operator hence serializing to string
710 assert result.str() == c2.str()
711 c1 = cmplx.complex(-3, 4)
712 c2 = cmplx.complex(-0.117501, 1.409921)
713 result = c1.atanh()
714 // Some issue with precision comparison in f64 using == operator hence serializing to string
715 assert result.str() == c2.str()
716 c1 = cmplx.complex(-1, -2)
717 c2 = cmplx.complex(-0.173287, -1.178097)
718 result = c1.atanh()
719 // Some issue with precision comparison in f64 using == operator hence serializing to string
720 assert result.str() == c2.str()
721}
722
723fn test_complex_acoth() {
724 // Tests were also verified on Wolfram Alpha
725 mut c1 := cmplx.complex(5, 7)
726 mut c2 := cmplx.complex(0.067066, -0.094740)
727 mut result := c1.acoth()
728 // Some issue with precision comparison in f64 using == operator hence serializing to string
729 assert result.str() == c2.str()
730 c1 = cmplx.complex(-3, 4)
731 c2 = cmplx.complex(-0.117501, -0.160875)
732 result = c1.acoth()
733 // Some issue with precision comparison in f64 using == operator hence serializing to string
734 assert result.str() == c2.str()
735 c1 = cmplx.complex(-1, -2)
736 c2 = cmplx.complex(-0.173287, 0.392699)
737 result = c1.acoth()
738 // Some issue with precision comparison in f64 using == operator hence serializing to string
739 assert result.str() == c2.str()
740}
741
742// fn test_complex_asech() {
743// // Tests were also verified on Wolfram Alpha
744// mut c1 := cmplx.complex(5,7)
745// mut c2 := cmplx.complex(0.094668,-1.503480)
746// mut result := c1.asech()
747// // Some issue with precision comparison in f64 using == operator hence serializing to string
748// assert result.str() == c2.str()
749// c1 = cmplx.complex(-3,4)
750// c2 = cmplx.complex(0.160446,-1.689547)
751// result = c1.asech()
752// // Some issue with precision comparison in f64 using == operator hence serializing to string
753// assert result.str() c2.str()
754// c1 = cmplx.complex(-1,-2)
755// c2 = cmplx.complex(0.396568,1.757114)
756// result = c1.asech()
757// // Some issue with precision comparison in f64 using == operator hence serializing to string
758// assert result.str() == c2.str()
759// }
760
761fn test_complex_acsch() {
762 // Tests were also verified on Wolfram Alpha
763 mut c1 := cmplx.complex(5, 7)
764 mut c2 := cmplx.complex(0.067819, -0.094518)
765 mut result := c1.acsch()
766 // Some issue with precision comparison in f64 using == operator hence serializing to string
767 assert result.str() == c2.str()
768 c1 = cmplx.complex(-3, 4)
769 c2 = cmplx.complex(-0.121246, -0.159507)
770 result = c1.acsch()
771 // Some issue with precision comparison in f64 using == operator hence serializing to string
772 assert result.str() == c2.str()
773 c1 = cmplx.complex(-1, -2)
774 c2 = cmplx.complex(-0.215612, 0.401586)
775 result = c1.acsch()
776 // Some issue with precision comparison in f64 using == operator hence serializing to string
777 assert result.str() == c2.str()
778}
779
780fn test_complex_re_im() {
781 c := cmplx.complex(2.1, 9.05)
782 assert c.re == 2.1
783 assert c.im == 9.05
784}
785