strtod() problem - bug in library?
Brian Fitzgerald
fitz at mml0.meche.rpi.edu
Thu Apr 18 10:51:48 AEST 1991
String-to-decimal conversion problem on AIX/370
------ -- ------- ---------- ------- -- -------
When a string equivalent to zero containing no decimal
point is encountered, strtod() does not store a pointer to
the unconverted suffix. Instead, it stores the same
pointer that was supplied, as though the conversion were
unsuccessful.
The AIX strtod() man page says that the decimal point is
optional.
Is my strtod function broken, is my code wrong, or am I
trying to do something non-portable or undefined?
If IBM has a bug fix, and you know the bug id number, or if
you have heard of this before, please send me e-mail or
post to this newsgroup. Thanks in advance.
Brian
/* tsd.c test string-to-decimal */
#include <stdio.h>
int main ()
{
char *s = "3.141593 1 -1 0.0 0 2.718282";
char *s1;
int i;
double d;
double strtod();
s1=s;
for(i=0;;i++) {
d = strtod(s, &s1);
if (s == s1) break;
(void) printf("i %i d %f\n", i , d);
s = s1;
}
return 0;
}
IBM 3090 Mainframe running AIX/370
% make tsd
cc -O tsd.c -o tsd
MetaWare High C Compiler R2.1r
(c) Copyright 1987-89, MetaWare Incorporated
% tsd
i 0 d 3.141593
i 1 d 1.000000
i 2 d -1.000000
i 3 d 0.000000 <-- why no more output?
Sparc IPC running SunOS 4.1.1
% make tsd
cc -target sun4 -o tsd tsd.c
% tsd
i 0 d 3.141593
i 1 d 1.000000
i 2 d -1.000000
i 3 d 0.000000
i 4 d 0.000000
i 5 d 2.718282
--
We need to secure as many banks in our computer banks as possible. We
don't want no one else's help, but yours. Miller's Comsumer Service
More information about the Comp.lang.c
mailing list