I'm confused: what's with atof?
Ok, I know the whole world can't have gone crazy overnight, so it must
be me. This program:
#include <stdio.h>
int main(int argc, char **argv)
{
char *sxxx = "1";
int xxx = atoi(sxxx);
char *sfoo = "1.0";
double foo = atof(sfoo);
double bar = 1.0;
double zot = foo + bar;
printf("xxx(%s) = %d, foo(%s) = %f, bar = %f, foo+bar = %f\n",
sxxx, xxx, sfoo, foo, bar, zot);
}
Does this:
xxx(1) = 1, foo(1.0) = 2147482232.000000, bar = 1.000000, foo+bar =
2147482233.000000
Note that the bizarre value that prints out is the same you'll get if
you type in "1.0" to one of the pastel/broken copies of emacs. emacs is
actually calling atof, down in read1(lread.c). But! On every system
I've tried, this breaks in a similar way: atoi works fine, atof prints
out something weird, but reproducible. I've tried this on Irix, x86
Linux, HP-UX, and LinuxPPC R4.
I'm obviously screwing up somehow (although you still have to wonder
about emacs). What am I doing wrong?
-Randy
--
http://www.cnbc.cmu.edu/~gobbel/
PGP fingerprint: 32 8A E8 24 A1 46 26 BC F9 9D 0E B6 81 A9 02 0C
NOTICE: I DO NOT ACCEPT UNSOLICITED COMMERCIAL EMAIL MESSAGES OF ANY
KIND.
Reply to: