在GHC / Haskell中可以使用扩展精度(80位)浮点运算吗? [英] Is it possible to use extended precision (80-bit) floating point arithmetic in GHC/Haskell?

查看:264
本文介绍了在GHC / Haskell中可以使用扩展精度(80位)浮点运算吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准的Haskell的 Double 使用


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 返回一个字符串,显示给定的小数类型 CReal 。


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆