<br><br>---------- Forwarded message ----------<br><span class="gmail_quote">From: <b class="gmail_sendername">Sean McLaughlin</b> <<a href="mailto:seanmcl@gmail.com">seanmcl@gmail.com</a>><br>Date: Jul 27, 2007 11:58 AM
<br>Subject: Re: [MLton-user] IEEEReal rounding not working<br>To: Matthew Fluet <<a href="mailto:fluet@tti-c.org">fluet@tti-c.org</a>><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) ^ "\n")<br>val _ = print(word8vectorToString (P.toBytes mtenth_hi) ^ "\n")<br>val _ = print(word8vectorToString (P.toBytes mtenth_near) ^ "\n")<br>val _ = print(word8vectorToString (
P.toBytes mtenth_zero) ^ "\n")</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. It seems every compiler I've seen
<br>the equivalent of atof, which rounds according to the rounding mode<br>at compile time. 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. <br>I'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)) ~~> false
<br><br>As a total amateur, I would say that some function like<br><br>val Real.roundFromString : string -> 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't know if the standard specifies this for 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'm not enough of an expert to offer advice on that
<br>issue. <br><br>Best,<br><span class="sg"><br>Sean<br><br><br><br><br><br><br><br><br><br><br><br>
</span>