exp in SBCL is wrong?

倖福魔咒の 提交于 2020-01-03 18:35:12

问题


CL-USER> (exp 1)
2.7182817

Why? It should be 2.7182818 (rounded from 2.7182818284590452353602874713526624977572470936999595749669...)

SBCL 1.0.29.11.debian


回答1:


It is a rounding error inherent in the IEEE single-float format.

CL-USER> (exp 1.0d0)
2.718281828459045d0



回答2:


Learn more about floating point arithmetic and its 'problems' in this classic paper (PDF):

What Every Computer Scientist Should Know About Floating-Point Arithmetic



来源:https://stackoverflow.com/questions/4771346/exp-in-sbcl-is-wrong

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!