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