[Haskell-cafe] Confused by ghci output

Lorenzo Bolla lbolla at gmail.com
Thu May 31 18:48:50 CEST 2012


It looks like you are overflowing `Int` with 3^40.
In your QuickCheck test, the function signature uses Int:

prop_sanemodexp :: Int -> Int -> Int -> Property

Note:
Prelude> 3^40
12157665459056928801
Prelude> 3^40 :: Int
689956897

Prelude> 3^40 `mod` 3
0
Prelude> (3^40 `mod` 3) :: Int
1


L.




On Thu, May 31, 2012 at 5:35 PM, Clark Gaebel <cgaebel at uwaterloo.ca> wrote:

> *X> 3^40 `mod` 3 == modexp2 3 40 3
> False
> *X> modexp2 3 40 3
> 0
> *X> 3^40 `mod` 3
> 0
>
> I'm confused. Last I checked, 0 == 0.
>
> Using GHC 7.4.1, and the file x.hs (which has been loaded in ghci) can be
> found here: http://hpaste.org/69342
>
> I noticed this after prop_sanemodexp was failing.
>
> Any help would be appreciated,
>   - Clark
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120531/d730b27f/attachment.htm>


More information about the Haskell-Cafe mailing list