-0 rational?

Levent Erkok erkokl at gmail.com
Mon Sep 18 00:48:44 UTC 2017


Moritz:

Looks like you're raising the same concern as in here:
https://ghc.haskell.org/trac/ghc/ticket/13124

Long story short: You cannot encode -0.0 directly. You have to represent it
as an expression, multiplying `-1` with `fromRational 0`.

Similar concerns apply to NaN and Infinity as well, though those cannot be
written as literals to start with, so it isn't a big issue there.

-Levent.

On Sun, Sep 17, 2017 at 7:02 AM, Moritz Angermann <
moritz.angermann at gmail.com> wrote:

> Hi *,
>
> I just ran into the following case:
>
> > fromRat (-0 :: Rational) :: Double
> 0.0
>
> > -0 :: Rational
> 0 % 1
>
> How do I encode negative zero as a rational? The question come
> up as `CmmFloat` is defined as `CmmFloat  Rational Width` in
> compiler/cmm/CmmExpr.hs. And my code generator thus turned
> (Int, Rational) into a floating point expression, and when trying
> to turn it into a `double` value, I ended up getting bad negative
> zeros.
>
> This makes me believe I can’t actually encode `-0` as a Rational,
> and such `CmmFloat` will never contain `-0`?
>
> Cheers,
>  Moritz
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20170917/9d9f583a/attachment.html>


More information about the ghc-devs mailing list