Yacoby
Yacoby

Reputation: 55465

Haskell 64 bit numerical type

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 ) )

Upvotes: 5

Views: 2474

Answers (3)

Don Stewart
Don Stewart

Reputation: 137987

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/

Upvotes: 21

Andrew Jaffe
Andrew Jaffe

Reputation: 27107

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

Upvotes: 0

Samir Talwar
Samir Talwar

Reputation: 14330

You want the Integer data type instead of Int:

addTwo :: Integer -> Integer -> Integer

Upvotes: 7

Related Questions