python提供的三角函數是對弧度進行運算,並且存在不確定尾數的情況,爲代碼簡潔及計算準確,利用原三角函數進行改寫,併爲計算精度,保留足夠有效位數。
import math
rad = 180 / math.pi
def sin(degree):
degree = degree / rad
sin = math.sin(degree)
return round(sin,15)
def cos(degree):
degree = degree / rad
cos = math.cos(degree)
return round(cos,15)
def tan(degree):
degree = degree / rad
tan = math.tan(degree)
return round(tan,15)
def asin(x):
asin = math.asin(x) * rad
return round(asin,14)
def acos(x):
acos = math.acos(x) * rad
return round(acos,13)
def atan(x):
atan = math.atan(x) * rad
return round(atan,16)
測試示例
sin(30) = 0.5
cos(60) = 0.5
tan(45) = 1.0