<br><br>---------- Forwarded message ----------<br><span class="gmail_quote">From: <b class="gmail_sendername">Sean McLaughlin</b> &lt;<a href="mailto:seanmcl@gmail.com">seanmcl@gmail.com</a>&gt;<br>Date: Jul 27, 2007 11:58 AM
<br>Subject: Re: [MLton-user] IEEEReal rounding not working<br>To: Matthew Fluet &lt;<a href="mailto:fluet@tti-c.org">fluet@tti-c.org</a>&gt;<br><br></span>Hi,<span class="q"><br><br><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>The other aspect that I was wondering about was floating-point constants.
<br>That is, what should the following program do:<br><br>val mtenth_lo = (down(); 0.1)<br>val mtenth_hi = (up(); 0.1)<br>val mtenth_near = (near(); 0.1)<br>val mtenth_zero = (zero(); 0.1)<br><br>val _ = print(word8vectorToString (
P.toBytes mtenth_lo) ^ &quot;\n&quot;)<br>val _ = print(word8vectorToString (P.toBytes mtenth_hi) ^ &quot;\n&quot;)<br>val _ = print(word8vectorToString (P.toBytes mtenth_near) ^ &quot;\n&quot;)<br>val _ = print(word8vectorToString (
P.toBytes mtenth_zero) ^ &quot;\n&quot;)</blockquote><div><br><br></div></div><br></span>From my experience with C compilers, I would never trust that writing<br>a [real] constant would round correctly.&nbsp; It seems every compiler I&#39;ve seen
<br>the equivalent of atof, which rounds according to the rounding mode<br>at compile time.&nbsp; A major concern then, is to have a safe way of getting<br>hold of a 64 bit floating point constant where you, in principle, know all 
<br>the bit values, say from the Mathematica RealDigits function.&nbsp; <br>I&#39;ve written a function like this that plays with PackRealBig.<br>Of course, it would be much nicer, and less error prone, to be able to write the above code.
<br>A very similar question is, what should this do?<br><br>(up();Math.pi) <br><br>It would be very strange to have a library constant like Math.pi have dynamic content...<br>Real.compare(Math.pi, (up();Math.pi)) ~~&gt; false
<br><br>As a total amateur, I would say that some function like<br><br>val Real.roundFromString : string -&gt; real option<br><br>that guarantees to respect the rounding mode is all that would be necessary<br>to do perfectly satisfactory mathematics with interval arithmetic.
<br>(I don&#39;t know if the standard specifies this for&nbsp; Real.fromString function...)<br>This would of course punt on trying to pin down the state of the Real and IEEEReal<br>structures wrt The Definition, but I&#39;m not enough of an expert to offer advice on that
<br>issue.&nbsp; <br><br>Best,<br><span class="sg"><br>Sean<br><br><br><br><br><br><br><br><br><br><br><br>
</span>