-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathtest_cmath.py
76 lines (67 loc) · 1.37 KB
/
test_cmath.py
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
from cmath import (exp, log, sqrt, acos, asin, atan, cos, sin, tan,
acosh, asinh, atanh, cosh, sinh, tanh,
phase, polar, rect)
from lpython import c64, c32, f64
def test_power_logarithmic():
x: c64
y: c64
x = complex(3, 3)
y = exp(x)
y = log(x)
y = sqrt(x)
a: c32
b: c32
a = c32(complex(3, 3))
b = exp(a)
b = log(a)
b = sqrt(a)
def test_trigonometric():
x: c64
y: c64
x = complex(3, 3)
y = acos(x)
y = asin(x)
y = atan(x)
y = cos(x)
y = sin(x)
y = tan(x)
a: c32
b: c32
a = c32(complex(3, 3))
b = acos(a)
b = asin(a)
b = atan(a)
b = cos(a)
b = sin(a)
b = tan(a)
def test_hyperbolic():
x: c64
y: c64
x = complex(3, 3)
y = acosh(x)
y = asinh(x)
y = atanh(x)
y = cosh(x)
y = sinh(x)
y = tanh(x)
a: c32
b: c32
a = c32(complex(3, 3))
b = acosh(a)
b = asinh(a)
b = atanh(a)
b = cosh(a)
b = sinh(a)
b = tanh(a)
def test_polar():
x: c64
eps: f64
eps = 1e-12
x = complex(1, -2)
assert f64(abs(f64(phase(x)) - (-1.1071487177940904))) < eps
assert f64(abs(f64(polar(x)[0]) - (2.23606797749979))) < eps
assert abs(abs(rect(2.23606797749979, -1.1071487177940904))-abs(x)) < eps
test_power_logarithmic()
test_trigonometric()
test_hyperbolic()
test_polar()