在GHC / Haskell中可以使用扩展精度(80位)浮点运算吗? [英] Is it possible to use extended precision (80-bit) floating point arithmetic in GHC/Haskell?
问题描述
data Double
双精度浮点数。希望这种类型至少在IEEE双精度类型的范围和精度上是相同的。
GHC / Haskell是否提供某处还有一些扩展精度(80位)浮点数,也许使用一些外部库?
正如chuff指出的那样,你可能想看一看数字包裹上。你可以用
cabal install numbers
来安装它。这里是一个例子:$ b $ pre $
import Data.Number.CReal - from数字
main :: IO()
main = putStrLn(showCReal 100(sqrt 2))
- output:1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727
正如文档指出, showCReal
返回一个字符串,显示给定的小数类型
The standard Haskell's Double uses the standard double-precision arithmetic:
data Double
Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.
Does GHC/Haskell offer somewhere also the extended precision (80-bit) floating point numbers, perhaps using some external library?
As chuff has pointed out, you might want to take a look a the numbers package on hackage. You can install it with cabal install numbers
. Here is an example:
import Data.Number.CReal -- from numbers
main :: IO ()
main = putStrLn (showCReal 100 (sqrt 2))
-- output: 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727
As the documentation states, showCReal
returns a string showing a given number of type CReal
with the given number of decimals.
这篇关于在GHC / Haskell中可以使用扩展精度(80位)浮点运算吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!