<div dir="ltr"><div>There's an existing ticket about this, filed 7 years ago: <a href="https://ghc.haskell.org/trac/ghc/ticket/3070">https://ghc.haskell.org/trac/ghc/ticket/3070</a></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 26, 2015 at 1:49 PM, Dominic Steinitz <span dir="ltr"><<a href="mailto:dominic@steinitz.org" target="_blank">dominic@steinitz.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have probably misunderstood but is the following expected? floor, round, truncate and ceiling give similar results (all methods of the RealFrac class).<br>
<br>
properFraction :: (Integral b, RealFrac a) => a -> (b, a)<br>
<br>
*Girsanov> properFraction (-1 / 0)<br>
(-17976931348623159077293051907890247336179769789423065727343008115773267<br>
5805500963132708477322407536021120113879871393357658789768814416622492847<br>
4306394741243777678934248654852763022196012460941194530829520850057688381<br>
5068234246288147391311054082723716335051068458629823994724593847971630483<br>
5356329624224137216,0.0)<br>
*Girsanov> properFraction (1 / 0)<br>
(179769313486231590772930519078902473361797697894230657273430081157732675<br>
8055009631327084773224075360211201138798713933576587897688144166224928474<br>
3063947412437776789342486548527630221960124609411945308295208500576883815<br>
0682342462881473913110540827237163350510684586298239947245938479716304835<br>
356329624224137216,0.0)<br>
*Girsanov> properFraction (0 / 0)<br>
(-26965397022934738615939577861835371004269654684134598591014512173659901<br>
3708251444699062715983611304031680170819807090036488184653221624933739271<br>
1459592111865666518401372982279144533294018691411791796244281275086532572<br>
2602351369432221086966581124085574502576602687944735992086890771957445725<br>
3034494436336205824,0.0)<br>
<br>
The Haskell Report "6.4.6 Coercions and Component Extraction" is<br>
silent on what to expect with NaN, Infinity and -Infinity so I think it should<br>
be amended. Alternatively, one could expect implementations to throw a<br>
runtime error?<br>
<br>
In ghc, the problem is here <a href="https://phabricator.haskell.org/D160a" rel="noreferrer" target="_blank">https://phabricator.haskell.org/D160a</a><br>
<br>
/* This is expected to replace uses of __decodeDouble_2Int() in the long run */<br>
StgInt<br>
__decodeDouble_Int64 (StgInt64 *const mantissa, const StgDouble dbl)<br>
{<br>
if (dbl) {<br>
int exp = 0;<br>
*mantissa = (StgInt64)scalbn(frexp(dbl, &exp), DBL_MANT_DIG);<br>
return exp-DBL_MANT_DIG;<br>
} else {<br>
*mantissa = 0;<br>
return 0;<br>
}<br>
}<br>
<br>
I believe frexp [1] and scalbn [2] both pass through NaN, Infinity and -Infinity and I<br>
think type coercion in C is undefined for these values.<br>
<br>
Furthermore exp is undefined for these values [1].<br>
<br>
1. <a href="http://en.cppreference.com/w/cpp/numeric/math/frexp" rel="noreferrer" target="_blank">http://en.cppreference.com/w/cpp/numeric/math/frexp</a><br>
2. <a href="http://en.cppreference.com/w/cpp/numeric/math/scalbn" rel="noreferrer" target="_blank">http://en.cppreference.com/w/cpp/numeric/math/scalbn</a><br>
<br>
Dominic Steinitz<br>
<a href="mailto:dominic@steinitz.org">dominic@steinitz.org</a><br>
<a href="http://idontgetoutmuch.wordpress.com" rel="noreferrer" target="_blank">http://idontgetoutmuch.wordpress.com</a><br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div>