GHC: Ticket #3134: encodeFloat . decodeFloat
http://ghc.haskell.org/trac/ghc/ticket/3134
<blockquote class="citation">
<p>
(0.0/0.0)
</p>
</blockquote>
<p>
NaN
</p>
<blockquote class="citation">
<p>
(uncurry encodeFloat . decodeFloat) (0.0/0.0)
</p>
</blockquote>
<p>
-Infinity
</p>
<p>
It seems reasonable to expect NaN here.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/3134
Trac 1.2simonmarThu, 02 Apr 2009 10:33:02 GMTdifficulty, milestone set
http://ghc.haskell.org/trac/ghc/ticket/3134#comment:1
http://ghc.haskell.org/trac/ghc/ticket/3134#comment:1
<ul>
<li><strong>difficulty</strong>
set to <em>Unknown</em>
</li>
<li><strong>milestone</strong>
set to <em>_|_</em>
</li>
</ul>
<p>
Interesting, I thought we had a very old ticket about this, but I can't seem to find it.
</p>
<p>
Anyway, I suppose the issue is what the representation of NaN and Infinity should be in the output of <code>decodeFloat</code>. There is no provision for NaN and Infinity in the Haskell definition of <code>encodeFloat</code> and <code>decodeFloat</code>:
</p>
<blockquote>
<p>
The function decodeFloat applied to a real floating-point number returns the
significand expressed as an Integer and an appropriately scaled exponent (an Int).
If decodeFloat x yields (m,n), then x is equal in value to mbn, where b is the
floating-point radix, and furthermore, either m and n are both zero or else
bd-1<=m<bd, where d is the value of floatDigits x. encodeFloat performs the
inverse of this transformation.
</p>
</blockquote>
<p>
from Section 6.4.6, <a class="ext-link" href="http://haskell.org/onlinereport/basic.html"><span class="icon"></span>http://haskell.org/onlinereport/basic.html</a>
</p>
TicketsimonmarMon, 06 Sep 2010 09:16:28 GMTfailure set
http://ghc.haskell.org/trac/ghc/ticket/3134#comment:2
http://ghc.haskell.org/trac/ghc/ticket/3134#comment:2
<ul>
<li><strong>failure</strong>
set to <em>None/Unknown</em>
</li>
</ul>
<p>
See also <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/3174" title="#3174: feature request: decodeFloat (0.0/0.0) = undefined (closed: duplicate)">#3174</a>
</p>
<p>
Maybe the right thing is for <code>decodeFloat</code> applied to <code>NaN</code> or <code>Infinity</code> to be an error, rather than silently succeeding with a bogus value.
</p>
Ticketdaniel.is.fischerThu, 14 Oct 2010 13:34:08 GMT
http://ghc.haskell.org/trac/ghc/ticket/3134#comment:3
http://ghc.haskell.org/trac/ghc/ticket/3134#comment:3
<p>
For the particular values which decodeFloat returns for NaNs (Float and Double), it would be easy to add a test to integer_cbits_encodeType, that would probably even be not too expensive.
</p>
<p>
However, those functions look a little dubious. Remind me to look at them again some time, maybe there's speed and correctness to be gained.
</p>
TicketekmettMon, 17 Nov 2014 21:13:01 GMTcc set
http://ghc.haskell.org/trac/ghc/ticket/3134#comment:4
http://ghc.haskell.org/trac/ghc/ticket/3134#comment:4
<ul>
<li><strong>cc</strong>
<em>ekmett</em> added
</li>
</ul>
TicketbgamariFri, 17 Jul 2015 16:27:37 GMT
http://ghc.haskell.org/trac/ghc/ticket/3134#comment:5
http://ghc.haskell.org/trac/ghc/ticket/3134#comment:5
<p>
daniel.is.fischer, perhaps you would like to have another look now?
</p>
Ticket