Haskell 64位数字类型

Yac*_*oby 5 numerical haskell types integer

我在Haskell中编写一个函数来处理超过32位int的数字.我找不到这种类型,我似乎在寻找错误的术语.

它需要能够保持大约2 ^ 40的数字,而不会损失任何精度

例:

addTwo :: Int -> Int -> Int
addTwo a b = a + b

main :: IO()
main = do
    putStrLn ( show ( addTwo 700851475143 1 ) )
Run Code Online (Sandbox Code Playgroud)

Don*_*art 21

对于无界精度,请使用Integer类型.对于64位精度,跨平台,使用Data.Int.Int64.使用Hoogle很容易找到两者:http://haskell.org/hoogle/


Sam*_*war 7

您想要Integer数据类型而不是Int:

addTwo :: Integer -> Integer -> Integer
Run Code Online (Sandbox Code Playgroud)