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

Re: reading a float?



In article <ravr9c1vx51.fsf@telnet.math.fu-berlin.de>, David Lichteblau
<lichtebl@math.fu-berlin.de> wrote:

> Unfortunately the C library doesn't have functions to decode and make
> floats, so Gwydion Dylan doesn't have them either.

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


> But adding these functions (to Gwydion Dylan) would introduce
> architecture-dependant code.  What do the maintainers of gd think about
> this issue?

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

I see four obvious general approaches:

1) punt and do whatever the C library on the given platform does
2) put together the mantissa as an exact integral float and then multiply
   by an appropriate power of ten.
3) assemble the float in final form using "multiply by ten and add
   the next digit" until you see the decimal then "multiply the scale
   factor by 0.1 and multiply by the next digit" there after.
4) do platform-specific bit-twiddling.


I'd rule out 4) as far too much work in porting.  I'd rule out 3) as being
far too innacurate due to rounding (and too slow).

2) is pretty good but won't let you create numbers really close to zero
unless you're very careful (and then you'll get multiple rounding errors).


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.  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?

-- Bruce



Follow-Ups: References: