*Test> ((3^40) `mod` 3) :: Int
2
*Test> ((3^40) `mod` 3)
0
Why is this so? I am using GHCi 7.0.3. If this is not a bug, an explanation of how Integral/Int works in haskell is appreciated, or a link to an explaination.
Thanks.
You're simply out of range, 3^40
is too big of a number to even fit in a 64-bit int:
Prelude> 3^40 :: Int
-6289078614652622815
Prelude> 3^40 :: Integer
12157665459056928801
The Integer
type on the other hand is unbounded and accepts all numbers no matter how big. In your second case (where you got a 0
result) you got a type Integer
inferred.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With