-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrigo_and_log.py
108 lines (89 loc) · 2.43 KB
/
trigo_and_log.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
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
# trigo_and_log.py
##############################################################################
# Imports #
##############################################################################
import math
from typing import Union
# Trigonometric Functions
def sin(x: Union[int, float]) -> float | None:
"""
Returns the sine of x (x in radians).
"""
try:
return math.sin(x)
except TypeError:
print("Input must be an integer or a float.")
return None
def cos(x: Union[int, float]) -> float | None:
"""
Returns the cosine of x (x in radians).
"""
try:
return math.cos(x)
except TypeError:
print("Input must be an integer or a float.")
return None
def tan(x: Union[int, float]) -> float | None:
"""
Returns the tangent of x (x in radians).
"""
try:
return math.tan(x)
except TypeError:
print("Input must be an integer or a float.")
return None
def arcsin(x: Union[int, float]) -> float | None:
"""
Returns the arc-sine of x.
"""
try:
return math.asin(x)
except TypeError:
print("Input must be an integer or a float.")
return None
def arccos(x: Union[int, float]) -> float | None:
"""
Returns the arc cosine of x.
"""
try:
return math.acos(x)
except TypeError:
print("Input must be an integer or a float.")
return None
def arctan(x: Union[int, float]) -> float | None:
"""
Returns the arc-tangent of x.
"""
try:
return math.atan(x)
except TypeError:
print("Input must be an integer or a float.")
return None
# Logarithmic and Exponential Functions
def ln(x: Union[int, float]) -> float | None:
"""
Returns the natural logarithm of x.
"""
try:
return math.log(x)
except TypeError:
print("Input must be an integer or a float.")
return None
def log2(x: Union[int, float]) -> float | None:
"""
Returns the base-2 logarithm of x.
"""
try:
return math.log2(x)
except TypeError:
print("Input must be an integer or a float.")
return None
def exp(x: Union[int, float]) -> float | None:
"""
Returns e raised to the power x.
"""
try:
return math.exp(x)
except TypeError:
print("Input must be an integer or a float.")
return None