Haskell 64 位数值类型
我正在 Haskell 中编写一个函数,用于处理超过 32 位 int 长度的数字。 我找不到执行此操作的类型,并且我似乎正在搜索错误的术语。
它需要能够保存长度约为 2^40 的数字而不损失任何精度
示例:
addTwo :: Int -> Int -> Int
addTwo a b = a + b
main :: IO()
main = do
putStrLn ( show ( addTwo 700851475143 1 ) )
I am writing a function in Haskell that deals with numbers beyond the length of a 32 bit int. I cannot find the type to do this and I seem to be searching for the wrong terms.
It needs to be able to hold numbers with the length of about 2^40 without any loss of precision
Example:
addTwo :: Int -> Int -> Int
addTwo a b = a + b
main :: IO()
main = do
putStrLn ( show ( addTwo 700851475143 1 ) )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于无限精度,请使用 Integer 类型。 对于跨平台的 64 位精度,请使用 Data.Int.Int64。 使用 Hoogle 可以轻松找到两者:http://haskell.org/hoogle/
For unbounded precision, use the Integer type. For 64 bits of precision, across platforms, use Data.Int.Int64. Both will be easy to find with Hoogle: http://haskell.org/hoogle/
您需要
Integer
数据类型而不是Int
:You want the
Integer
data type instead ofInt
:使用精度不受限制的
Integer
,而不是Int
。Use
Integer
, which is unlimited precision, instead ofInt
.