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

Re: reading a float?



brucehoult@pobox.com (Bruce Hoult) writes:

> Decode and make them from *what*?  The standard C library certainly has
> functions that parse a string and produce a float.

> Are you talking about putting together the binary representation of a
> float by using bit-twiddling instructions?  Ick.

You are right.  Using atof(3) is probably the best solution--I was
replying to Chris' suggestion talking about an implementation in Common
Lisp or Dylan, and I was thinking about _printing_ floats, too.  When I
translated CMUCL's implementation of FORMAT to Dylan I couldn't figure
out how to do flexible floating-point printing portably (and that part
is still broken/missing), so my idea was that if ``bit-twiddling'' was
needed anyway (for printing) then reading floats could be done in Dylan
as well.

> It's hard to see how you can go past 1).  Doing this properly is actually
> far harder than I've intimated above -- people actually write academic
> papers on the subject.

Given portable bit-twiddling-functions it's as easy as implementing the
algorithms presented in these papers.

> Someone's already done the hard work of getting
> fast, accurate FP conversions to work on any machine that has a C
> compiler.    Why not use it?

I didn't find a way to use it for printing.  Patches or hints are
welcome.



Follow-Ups: References: