[gambit-list] How emulate #e using inexact->exact or something?

Bradley Lucier lucier at math.purdue.edu
Mon Dec 23 21:11:36 EST 2013


On 12/23/2013 07:44 PM, Mikael wrote:
> Dear Marc or Brad,
>
> First - Happy Holidays! :))
>
> A Q:
>
> > #e0.3
> 3/10
> > (inexact->exact 0.3)
> 5404319552844595/18014398509481984
>
>
> > #e0.2
> 1/5
> > (inexact->exact 0.2)
> 3602879701896397/18014398509481984
>
>
> Why the different results? Is there any way to get the #e behavior in 
> a more effective way than (string-append "#e" (number->string n))?

I don't think so.  inexact->exact works on numbers, the #e notation 
works on strings.  The reader turns "0.3" by default into 
5404319552844595/18014398509481984, the closest floating-point 64-bit 
binary number to 0.3.

I did exactly the trick of appending "#e" to the front of numerical 
strings for a homework-on-the-web system that I wrote when the students 
expected to use exact decimal arithmetic.

See:

 > (- .3 3/10)
0.
 > (= .3 3/10)
#f

Brad



More information about the Gambit-list mailing list