Haskell 64 位数值类型

发布于 2024-07-24 02:18:33 字数 282 浏览 3 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最舍不得你 2024-07-31 02:18:33

对于无限精度,请使用 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/

酸甜透明夹心 2024-07-31 02:18:33

您需要 Integer 数据类型而不是 Int

addTwo :: Integer -> Integer -> Integer

You want the Integer data type instead of Int:

addTwo :: Integer -> Integer -> Integer
时光磨忆 2024-07-31 02:18:33

使用精度不受限制的 Integer,而不是 Int

Use Integer, which is unlimited precision, instead of Int.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文