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

Re: reading a float?



In article <38FF2C46.D8580EF8@miqs.com>, Scott Ribe <sribe@miqs.com> wrote:

> Bruce Hoult wrote:
> > 
> > 1) punt and do whatever the C library on the given platform does
> 
> It's been implied that this may be somewhat limited and not cover all
> formats? If so, I would think the answer is obvious: Dylan code to
> reduce the input string to a canonical representation, followed by C
> library conversion.

Right.

I just took a look at the CodeWarrior library source code (which they
kindly give you) to see what they do in atof.  Basically they've got a
state machine that parses the float and puts it in a canonical form into a
MacOS "Decimal" structure...

struct decimal {
    char sgn;                           /*sign 0 for +, 1 for -*/
    char unused;
    short exp;                          /*decimal exponent*/
    struct{
        unsigned char length;
        unsigned char text[SIGDIGLEN];  /*significant digits */
        unsigned char unused;
        }sig;
};

... and then uses the MacOS str2num function.  Which I'm quite sure will
Get It Right -- Apple has cared about precise FP with the SANE (Standard
Apple Numeric Environment) right since the Apple ][ ProDOS days.

-- Bruce



References: