[Haskell-cafe] Arithmetic overflow

Levent Erkok erkokl at gmail.com
Fri Jan 24 16:42:44 UTC 2014


I think this is a bug. It also seems to impact explicitly sized types:

Prelude Data.Int> (minBound::Int8) `quot` (-1)
*** Exception: arithmetic overflow
Prelude Data.Int> (minBound::Int16) `quot` (-1)
*** Exception: arithmetic overflow

You should definitely report it. I think there's a pending release of GHC,
so they might be able to fix it shortly.

-Levent.


On Thu, Jan 23, 2014 at 10:33 PM, Rob Leslie <rob at mars.org> wrote:

> Greetings,
>
> I have a question about arithmetic overflow in Haskell -- actually,
> probably specifically in GHC.
>
> It’s my understanding from the Haskell 2010 Language Report that “The
> results of exceptional conditions (such as overflow or underflow) on the
> fixed-precision numeric types [e.g. Int] are undefined; an implementation
> may choose error (⊥, semantically), a truncated value, or a special value
> such as infinity, indefinite, etc.”
>
> In the documentation for Data.Int from the current release of the Haskell
> Platform, I read that “All arithmetic is performed modulo 2^n, where n is
> the number of bits in the type.”
>
> However, there seems to be at least one exception to this promise, namely:
>
>   λ> (minBound :: Int) `quot` (-1)
>   *** Exception: arithmetic overflow
>
> Is this a bug?
>
> More specifically, is it intended to be safe to rely on the modulo
> arithmetic behavior of GHC in spite of the Language Report? And if so,
> should the above witnessed behavior still be expected?
>
> Thanks,
>
> --
> Rob Leslie
> rob at mars.org
>
>
> _______________________________________________
> 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/20140124/fe6e0c06/attachment.html>


More information about the Haskell-Cafe mailing list