guile-user
[Top][All Lists]

## number->string radix patch (Was Re: First look at Guile Std Library avai

 From: Richard Todd Subject: number->string radix patch (Was Re: First look at Guile Std Library available) Date: Tue, 6 Jan 2004 12:41:16 -0600 User-agent: Mutt/1.4i

```On Mon, Jan 05, 2004 at 06:36:07PM -0700, Robert Uhl wrote:
> Although my one true project is to figure out number->string well enough
> to make it Do the Right Thing for decimals in bases other than 10 (I'm a
> big fan of duodecimal).

I've seen this wish twice from you in the short time I've been
watching guile-user, so I took a crack at it.  You are right, the
algorithm is hard to follow, but I think I worked it out.  I only
tested it by typing in random numbers and eyeballing the results, so
if you don't mind try it out and let me know if you get bad answers.

The patch should apply to CVS guile.
(supports the full 2 -> 36 radix range that integers enjoyed)

(PS I used CAPS for the letters since, as the last two examples show,
you need a way to differentiate the 'e' and 'i' from the digits in the
number.  Should this patch ever make it into guile, maybe all
string->number operations should switch to uppercase.)

Example:
guile> (number->string 35.25 36)
"Z.9"
guile> (number->string 0.25 2)
"0.01"
guile> (number->string 255.0625 16)
"FF.1"
guile> (number->string (/ 1 3) 3)
"1/10"
guile> (number->string 11.33333333333333333 12)
"B.4"
guile> (number->string 11.33333333333333333+23i 12)
"B.4+1B.0i"
guile> (number->string 1.324e44 16)
"5.EFE0A14FAFEe24"

Richard Todd
richardt at vzavenue dot net```