exp in SBCL is wrong?

2019-06-24 04:00发布

CL-USER> (exp 1)
2.7182817

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

SBCL 1.0.29.11.debian

标签: lisp sbcl
2条回答
2楼-- · 2019-06-24 04:52

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

What Every Computer Scientist Should Know About Floating-Point Arithmetic

查看更多
相关推荐>>
3楼-- · 2019-06-24 05:03

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

CL-USER> (exp 1.0d0)
2.718281828459045d0
查看更多
登录 后发表回答