-
Notifications
You must be signed in to change notification settings - Fork 0
/
trig.py
45 lines (45 loc) · 1.18 KB
/
trig.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
#####trig.py
# Return accurate results from trig functions
# Takes degrees values by default
#
import math
#
def sin(args):
args = float(args) #redundancy float conversion
if(args%180==0):
return float(0)
else:
return math.sin(math.radians(args))
#
def cos(args):
args = float(args) #redundancy float conversion
if(((args*2-180)/360).is_integer()):
return float(0)
else:
return math.cos(math.radians(args))
#
def tan(args):
args = float(args) #redundancy float conversion
if(args%180==0):
return float(0)
elif(((args*2-180)/360).is_integer()):
return "undefined"
elif(((4*args-180)/720).is_integer()):
return float(1)
elif(((4*args-3*180)/720).is_integer()):
return float(-1)
else:
return math.tan(math.radians(args))
#
def cot(args):
args = float(args) #redundancy float conversion
if(((args*2-180)/360).is_integer()):
return float(0)
elif(args%180==0):
return "undefined"
elif((4*args-180)/720).is_integer():
return float(1)
elif((4*args-3*180)/720).is_integer():
return float(-1)
else:
return float(cos(args)/sin(args))