Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我试图在 python 控制台中检查欧拉的身份:
import math import cmath cmath.exp(1j*math.pi)
结果是:
-1+1.2246063538223773e-16j
它不应该只是-1。
这对我来说已经足够接近了——尤其是因为math.pi它不是无限精确的——考虑到这一点,如果它给了你,这实际上是错误的答案-1+0j。
math.pi
-1+0j
想象一下,你正在做这个计算,但你开始时只有 5 位 pi,然后在每个阶段都四舍五入到 5 位有效数字。你认为你会得到一个准确的答案吗?不,当然不是,每个阶段的微小错误都会在答案中产生错误。
浮点数学是相同的,只是这次您使用的是二进制而不是十进制。