data Double双精度浮点数.希望这种类型在范围和精度上至少与IEEE双精度类型相同.
GHC/Haskell是否也提供扩展精度(80位)浮点数,也许使用一些外部库?
floating-point haskell ghc floating-point-precision extended-precision
在ghci终端中,我使用sqrt函数计算了一些使用Haskell的方程式.
我注意到sqrt,当我的结果被简化时,我有时会失去精确度.
例如,
sqrt 4 * sqrt 4 = 4 -- This works well!
sqrt 2 * sqrt 2 = 2.0000000000000004 -- Not the exact result.
Run Code Online (Sandbox Code Playgroud)
通常情况下,我会期待结果2.
有没有办法获得正确的简化结果?
这在Haskell中如何工作?