[gambit-list] Any rational-number->string with infinite precision for decimal output? (i.e. d.ddddd rather than x/y)

Mikael mikael.rcv at gmail.com
Wed Jan 15 12:58:21 EST 2014


Ah, actually this can be implemented for #e12345.6789 by first flooring and
printing that out ("12345") then deducting that from the value (=> 0.6789)
and then doing * 10 and |truncate| up to eq? 0 - that works. Perhaps it'd
even be quite close to optimum speed?

I.e. #e12345.6789 (floor #) (- ## #) , and then repeat (eq? # 0) (* ## 10)
(truncate #) (- ## #).






2014/1/15 Mikael <mikael.rcv at gmail.com>

> Dear Brad or Marc and list,
>
> Curious, so you can parse into Gambit a decimal number with infinite
> precision, with exactness, by just appending "#e" to it i.e. > (define
> (string->exact-number s) (string->number (string-append "#e" s)))
> > (string->exact-number "1.23478289348923749872394728934")
> 61739144674461874936197364467/50000000000000000000000000000
>
> Is there any way to do the opposite? All I see number->string give is
> "61739144674461874936197364467/50000000000000000000000000000"
>
> - how would the definition of an exact-number->string look that produced
> an output with decimals,
> i.e. something that gave "1.23478289348923749872394728934" or
> "#e1.23478289348923749872394728934" back?
>
> I understand there are cases with unlimited number of decimals i.e. 1/3, a
> typechecker for that would be awesome.
>
> Thanks,
> Mikael
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20140115/4024a25d/attachment.htm>


More information about the Gambit-list mailing list