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

Re: reading a float?



On Wed, 19 Apr 2000, Bruce Hoult wrote:
> In article <hX8L4.6255$QX1.232123@typhoon.ne.mediaone.net>, "Scott McKay"
> <swm@mediaone.net> wrote:
> > Amazingly, there doesn't appear to be ... string-to-float.  I guess
> > it's time for someone to write one! 

The only reason I (very vaguely) remember hearing for this omission was (I
think) from David Gray at Harlequin, when we were talking about adding it
for Harlequin Dylan.  IIRC he said that there are various slightly-
incompatible printed formats for floating-point numbers; so it's much
easier to do a "correct" float-to-string (i.e., one whose output matches
many other programs) than to do a "complete" string-to-float (i.e., one
which reads floats in as many of the "common" formats as possible).  I
think there was also some concern about it being a largish function to
write and hence bloating whichever library we were thinking of adding it
to.  It does seem like an odd omission, though. 

I don't remember what these slightly different formats were, though.  At
the very least a string-to-float should parse the output from
float-to-string.  It might be nice if it parsed C's format, if that's
different.  Or maybe something extensible like the CL reader thing Chris
Double mentioned in another followup; someone might want string-to-double
or string-to-arbitrary-precision-float or string-to-complex or ... later.

> OK, well that part is easy enough if we punt to C:

... provided atof parses all output from float-to-string.

> Now, where to put it?

Preferably wherever float-to-string and/or string-to-integer live, unless
there's some good reason against it (e.g., huge bloat), I'd say.

Hugh





References: