Skip to main content
 首页 » 编程设计

python之math.sin 和 math.cos 中的不同精度

2024年11月01日7小虾米

我有一个关于在 python 中计算辐射的 sin 和 cos 的简单问题。

在我看来,sin 仅限于大于“x.xe-8”的值,而 cos 能够计算小得多的值,例如我示例中的“x.xe-90”。

有没有办法(除了 sin 之前的 round)让 sin 正常工作(当然在它的精度范围内)。

>>> import math 
>>> math.sin(1.0e-8) 
1e-08 
>>> math.sin(1.0e-9) 
Traceback (most recent call last): 
  File "<stdin>", line 1, in <module> 
ValueError: math domain error 
>>> math.cos(1.0e-90) 
1.0 

编辑:问题出在操作系统上。有可用的更新。 ( https://www.suse.com/support/update/announcement/2012/suse-ru-20120681-1.html )

请您参考如下方法:

问题出在操作系统上。有可用的 Suse Enterprise 11.2 更新。 --> https://www.suse.com/support/update/announcement/2012/suse-ru-20120681-1.html