为什么在Common Lisp中,当我运行函数“ acos”时,参数为1,答案是否错误? [英] Why in Common Lisp, when I run the function "acos" with an argument of 1, is the answer is wrong?
问题描述
我在运行(acos 1)时找到了1个emacs的ArcCosine,而不是正确答案0,而是得到了答案
instead of the correct answer of 0 when I run (acos 1) in, to find the ArcCosine of 1 emacs, I get the answer
-6.125742f-17
这是为什么?如何获得正确的0答案,如Windows计算器所说的那样
why is that and how do I get the correct answer of 0 like Windows Calculator says it should be
我正在使用SBCL作为Windows 8上的Lisp解释器,并且SBCL是32位的
I'm using SBCL as my Lisp Interpreter on Windows 8 and SBCL is 32-BIT
:
(acos(理性1))
我得到相同的答案,当我运行
i get the same answer and when I run
(acos(float 1))
我收到此错误
The value -6.1257422745431e-17
is not of type
(DOUBLE-FLOAT 0.0 3.141592653589793).
[Condition of type TYPE-ERROR]
推荐答案
对 sin(M_PI)也不为0 在这里也适用:
您需要阅读每个计算机科学家应了解的浮点算法,并意识到所有浮点计算都是近似的,并且
You need to read What Every Computer Scientist Should Know About Floating-Point Arithmetic and realise that all floating point computations are approximate and the approximation you got is "good enough".
对于 SBCL
错误,您应该将其报告给SBCL维护者。
这篇关于为什么在Common Lisp中,当我运行函数“ acos”时,参数为1,答案是否错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!