-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
>>> 0.4-0.3 结果为啥是 0.10000000000000003 #30
Comments
知道了 |
虽然 @Cuick 已经找到了答案,写一下自己的理解:
上面代码直接展示了
也就是说在 为什么这么说呢? 因为不是所有的浮点数都有二进制的精确表示,并且浮点数的二进制位数有限制,所以会存在多个浮点数对应一个二进制的情况(实际就是一个浮点数二进制对应了实数域的一个连续区间,该区间内的浮点数都会映射到这个二进制表示),比如:
上面那个不引起混乱的规则就是将输出的值反过来代入 ref |
二进制表示浮点数会有截断误差 就是精度的问题 是正常的 |
有没有大佬解释一下这是啥原因呢?
The text was updated successfully, but these errors were encountered: