[comp.lang.c] strtod

peter@athena.mit.edu (Peter J Desnoyers) (07/21/88)

If anyone needs an implementation of strtod or strtol, I have a
version I wrote. (first for bsd porting, then on sys5 with strtod bug)
It probably isn't hyper-fast, but it works. Please email me - I'll
post if I get enough response.

				Peter Desnoyers
				peter@athena.mit.edu
				eddie!athena!peter (I think)

fitz@mml0.meche.rpi.edu (Brian Fitzgerald) (04/18/91)

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

slh@gibdo.engr.washington.edu () (04/23/91)

In article <5!mgj6f@rpi.edu> fitz@mml0.meche.rpi.edu (Brian Fitzgerald) writes:
|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.
|
	strtoul() also seems to be incorrect:
	if integer can not be formed, addr before string is returned in pointer
	and not string

jfh@greenber.austin.ibm.com (John F Haugh II) (04/24/91)

In article <5!mgj6f@rpi.edu> fitz@mml0.meche.rpi.edu (Brian Fitzgerald) writes:
>The AIX strtod() man page says that the decimal point is
>optional.

Yes, it is.  And single digits (your "1", for example) work
just fine.  The problem only occurs with a single "0" digit.

>Is my strtod function broken, is my code wrong, or am I
>trying to do something non-portable or undefined?

I've located the bug and requested that it be APAR'd.  Thanks
for sending in the bug report.
-- 
John F. Haugh II      |      I've Been Moved     |    MaBellNet: (512) 838-4340
SneakerNet: 809/1D064 |          AGAIN !         |      VNET: LCCB386 at AUSVMQ
BangNet: ..!cs.utexas.edu!ibmchs!auschs!snowball.austin.ibm.com!jfh (e-i-e-i-o)