Mar*_*ark 3 python precision trigonometry decimal
在Python 2.6,我发现的十进制值sqrt(pi)是
Decimal(pi).sqrt()
Run Code Online (Sandbox Code Playgroud)
是否有类似sin,cos或其他(反)三角函数的东西?
该文档只提及如何计算cos和sin计算.Decimal(pi).cos()不存在也不存在from decimal import cos
更新:使用默认三角函数的问题是,Decimal如果我每次想要计算某些东西时将它们从float和back转换它就会失败.(同时Decimal在每个计算周围输入都很烦人,但我想我可以做一个包装函数)
触发功能在数学模块中
所以:
>>> decimal.Decimal(math.cos(0.1))
Decimal('0.99500416527802570954008842818439006805419921875')
Run Code Online (Sandbox Code Playgroud)
如果要在Python中寻找支持Trig函数的多精度数学库,则不是Decimal。看一下mpmath。Mpmath支撑三角函数在任意精度; 十进制没有。