[comp.unix.aix] strtod

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)

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

In article <1991Apr23.071505.16713@gibdo.engr.washington.edu> slh@gibdo.engr.washington.edu (PUT YOUR NAME HERE) writes:
>	strtoul() also seems to be incorrect:
>	if integer can not be formed, addr before string is returned in pointer
>	and not string

I wasn't able to even find strtoul() on AIX 1.2, so I wasn't able to
test your assertion regarding strtoul().  I did, however, test it
against strtol() and found that it behaves incorrectly.  In particular,

	char *end;

	strtol ("  hi mom!", &end, 0);

declares that "  hi mom!" is a valid integer with value 0 by returning
'end' as a pointer to "hi mom!", which then fails.  I have requested
that strtol() be fixed.  If you can get more information concerning
strtoul(), please let me know.
-- 
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)

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

In article <7036@awdprime.UUCP> jfh@greenber.austin.ibm.com (John F Haugh II) writes:
>In article <1991Apr23.071505.16713@gibdo.engr.washington.edu> slh@gibdo.engr.washington.edu (PUT YOUR NAME HERE) writes:
|>	strtoul() also seems to be incorrect:
|>	if integer can not be formed, addr before string is returned in pointer
|>	and not string
|
|I wasn't able to even find strtoul() on AIX 1.2, so I wasn't able to
|test your assertion regarding strtoul().  I did, however, test it
|against strtol() and found that it behaves incorrectly.  In particular,
|
|	char *end;
|
|	strtol ("  hi mom!", &end, 0);
|
|declares that "  hi mom!" is a valid integer with value 0 by returning
|'end' as a pointer to "hi mom!", which then fails.  I have requested
|that strtol() be fixed.  If you can get more information concerning
|strtoul(), please let me know.
	The problem is exactly as I stated (AIX3.1, including I think 3005);
	if the anumber can't be formed, the addr just before the beginning
	of the string is returned, rather than the addr of the string.
	I don't remember if this happens only when the first char
	terminates the translation (which is what I suspect and makes sense)
	or if it always happens in this situation.
	I've already written a note in the little ibm bug database.