<div dir="ltr"><div class="gmail_extra">2013/12/24 Bradley Lucier <span dir="ltr"><<a href="mailto:lucier@math.purdue.edu" target="_blank">lucier@math.purdue.edu</a>></span><br></div><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On 12/23/2013 07:44 PM, Mikael wrote:<br>

> Dear Marc or Brad,<br>
><br>
> First - Happy Holidays! :))<br>
><br>
> A Q:<br>
><br>
> > #e0.3<br>
> 3/10<br>
> > (inexact->exact 0.3)<br>
> 5404319552844595/18014398509481984<br>
><br>
><br>
> > #e0.2<br>
> 1/5<br>
> > (inexact->exact 0.2)<br>
> 3602879701896397/18014398509481984<br>
><br>
><br>
> Why the different results? Is there any way to get the #e behavior in<br>
> a more effective way than (string-append "#e" (number->string n))?<br>
<br>
</div>I don't think so.  inexact->exact works on numbers, the #e notation<br>
works on strings.  The reader turns "0.3" by default into<br>
5404319552844595/18014398509481984, the closest floating-point 64-bit<br>
binary number to 0.3.<br></blockquote><div><br></div><div>Aha so it boils down to be two completely different underlying algorithms - interesting.</div><div><br></div><div>Wait, just curious, what is the actual FP 64bit representation of 0.3 and why does it turn out differently like this?</div>

<div><br></div><div>(and (exact->inexact 5404319552844595/18014398509481984) become .3 rather than 0.299[something] or 0.3000[something])</div><div><br></div><div><br></div><div>Am having a use case where exact arithmetics are wanted and the precision in decimals is fixed anyhow.</div>

<div><br></div><div>Perhaps using integers and using the lowest digits as decimals makes the most sense?</div><div><br></div><div>(as using FP:s seem to lead to weird complexities like this one, automatic disappearance of digits in some cases, and perhaps some potential formatting issue re automatic switching over to scientific notation)</div>

<div><br></div><div>Is a bit unfortunate as integers-as-decimal-numbers isn't too concise, needing to remember that 2345 really means 23.45 and so on.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

I did exactly the trick of appending "#e" to the front of numerical<br>
strings for a homework-on-the-web system that I wrote when the students<br>
expected to use exact decimal arithmetic.<br></blockquote><div><br></div><div>Mhm.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<br>
See:<br>
<br>
 > (- .3 3/10)<br>
0.<br>
 > (= .3 3/10)<br>
#f<br>
<br>
Brad<br>
_______________________________________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
</blockquote></div><br></div></div>