Hello,<br><br>&nbsp; Thanks again for the fix.&nbsp; I found another quirk though:<br><br>Seems like fromString is going the wrong way for negative numbers.<br><br>&nbsp; structure I = IEEEReal<br>&nbsp; structure R = Real&nbsp; <br>&nbsp; structure V = Word8Vector
<br>&nbsp; structure P = PackRealBig<br><br>&nbsp; fun down() = I.setRoundingMode I.TO_NEGINF<br>&nbsp; fun up() = I.setRoundingMode I.TO_POSINF<br><br>&nbsp; fun word8vectorToString v = V.foldr (fn(w,s) =&gt; Word8.toString w ^ s) &quot;&quot; v
<br><br>&nbsp; val _ = down()<br>&nbsp; val x = ~1.0/10.0<br>&nbsp; val _ = up()<br>&nbsp; val y = ~1.0/10.0<br>&nbsp; val _ = if R.&lt;=(x,y) then print &quot;YES\n&quot; else print &quot;NO\n&quot;<br>&nbsp; val _ = print(word8vectorToString (P.toBytes
 x) ^ &quot;\n&quot;)<br>&nbsp; val _ = print(word8vectorToString (P.toBytes y) ^ &quot;\n&quot;)<br><br>&nbsp; val s = &quot;~0.1&quot;<br>&nbsp; val _ = down()<br>&nbsp; val x = Option.valOf (Real.fromString s)<br>&nbsp; val _ = up()<br>&nbsp; val y = 
Option.valOf (Real.fromString s)<br>&nbsp; val _ = if R.&lt;=(x,y) then print &quot;YES\n&quot; else print &quot;NO\n&quot;<br>&nbsp; val _ = print(word8vectorToString (P.toBytes x) ^ &quot;\n&quot;)<br>&nbsp; val _ = print(word8vectorToString (
P.toBytes y) ^ &quot;\n&quot;)<br><br>~/save/versioned/projects/kepler/sml<br>$ YES<br>BFB999999999999A<br>BFB9999999999999<br>NO<br>BFB9999999999999<br>BFB999999999999A<br><br>Is this something you&#39;d be interested in fixing, though the Definition doesn&#39;t
<br>specify rounding behavior for fromString, or shall I just avoid fromString<br>as well as I can?<br><br>Thanks!<br><br>Sean<br><br><br><br><div><span class="gmail_quote">On 7/29/07, <b class="gmail_sendername">Matthew Fluet
</b> &lt;<a href="mailto:fluet@tti-c.org">fluet@tti-c.org</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On Fri, 27 Jul 2007, Sean McLaughlin wrote:
<br>&gt;&gt; From my experience with C compilers, I would never trust that writing<br>&gt; a [real] constant would round correctly.&nbsp;&nbsp;It seems every compiler I&#39;ve seen<br>&gt; the equivalent of atof, which rounds according to the rounding mode
<br>&gt; at compile time.&nbsp;&nbsp;A major concern then, is to have a safe way of getting<br>&gt; hold of a 64 bit floating point constant where you, in principle, know all<br>&gt; the bit values, say from the Mathematica RealDigits function.
<br>&gt; I&#39;ve written a function like this that plays with PackRealBig.<br><br>I think that bouncing through PackReal is the portably way of getting<br>exactly the bits you want.<br><br>&gt; A very similar question is, what should this do?
<br>&gt;<br>&gt; (up();Math.pi)<br>&gt;<br>&gt; It would be very strange to have a library constant like Math.pi have<br>&gt; dynamic content...<br><br>Yes that would be strange, and somewhat inconsistent with the semantics of
<br>the language.&nbsp;&nbsp;Math.pi is an immutable value -- one that never changes.<br>The binding of Math.pi to a value occurs when the Math structure is<br>evaluated, so occurs according to the initial rounding mode.<br>One might have:
<br>&nbsp;&nbsp; Math.roundPi : unit -&gt; real<br>that gives you pi according the the current rounding mode, but the<br>explicit thunk makes it clear that it is somehow context dependent.<br><br>&gt; Real.compare(Math.pi, (up();Math.pi)) ~~&gt; false
<br>&gt;<br>&gt; As a total amateur, I would say that some function like<br>&gt;<br>&gt; val Real.roundFromString : string -&gt; real option<br>&gt;<br>&gt; that guarantees to respect the rounding mode is all that would be necessary
<br>&gt; to do perfectly satisfactory mathematics with interval arithmetic.<br>&gt; (I don&#39;t know if the standard specifies this for&nbsp;&nbsp;Real.fromStringfunction...)<br><br>I think the Real.{to,from}Decimal are the closest, though the Basis
<br>Library explicitly states that the conversions occur under TO_NEAREST.<br>I believe that the Real.fromString function works according to the current<br>rounding mode.<br><br></blockquote></div><br>