[Prev][Next][Index][Thread]

Re: Floats and Strings



In article <200105050915.FAA22278@life.ai.mit.edu>, Rob Myers
<robmyers@mac.com> wrote:

| I've added code for float-to-string and an unofficial (non-standard) 
| string-to-float into gd/src/common/common-dylan/extentions.dylan.
| It's not amazingly elegant code but it works. :-)

I don't know if you already looked at this or not, but if you want a
really good float-to-string algorithm, see:

   http://citeseer.nj.nec.com/28233.html

"Printing Floating Point Numbers Quickly and Accurately" by Burger and Dybvig.

This algorithm generates the shortest, correctly rounded output string
that converts to the same number when read back in.  It is used in many
Scheme and Lisp implementations, and I used it as the basis for the Squeak
Smalltalk Float printing method.

If you use double-precision float values in the implementation, rather
than the unlimited precision integers, it will run much faster, and only
lose about 3 ulps (Unit of Least Precision) of accuracy.

-- 

     -- Tim Olson