Opened 16 years ago

Closed 15 years ago

#3593 closed bug (fixed)

strtod doesn't support "INF" input

Reported by: Adek336 Owned by: axeld
Priority: normal Milestone: R1
Component: System/libroot.so Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

#include <stdio.h>
#include <stdlib.h>

int main()
{
	char * endptr;
	double d = strtod("inf", &endptr);
	fprintf(stderr, "%f '%s'\n", d, endptr);
	return 0;
}

http://www.opengroup.org/onlinepubs/000095399/functions/strtod.html:[[br]]

The expected form of the subject sequence is an optional plus or minus sign, then one of the following:

[...]

* One of INF or INFINITY, ignoring case
* One of NAN or NAN(n-char-sequenceopt), ignoring case in the NAN part, where:[...]

Change History (3)

comment:2 by Adek336, 16 years ago

Additionaly, strtod failed with this testcase

#include <stdio.h>
#include <stdlib.h>

int main()
{
   double d = strtod("+8E153", NULL);
   printf("%.10e\n", d);
   return 0;
}

Linux result: 8.0000000000e+153
Haiku result: 7.9999999873e+153
The testcase is inspired by the results of running "python test_float.py" for the floating point test.
Both python 2.6 on Haiku-gcc4 and python 2.7 on Haiku-gcc2 we print the following message -

[...]
    self.assertEqual(v, eval(repr(v)))
AssertionError: 7.9999999872500254e+153 != 7.9999999745000492e+153


The test which errors out in python is equivalent to

x = "+8E153"
v = eval(x)
assert v == eval(repr(v))

So it looks like #3308 's test_float.py issue is caused by problems with strtod(). Our implementation comes from FreeBSD. The following is the last revision of their stdtod.c file; in later revisions, FreeBSD uses gdtoa ( http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gdtoa/ link to NetBSD gdtoa as I couldn't find an online viewable FreeBSD link ): http://svn.freebsd.org/viewvc/base/head/lib/libc/stdlib/strtod.c?revision=106918&view=markup&pathrev=112256

However, importing rev 112256 of FreeBSD's strtod.c into the Haiku tree and doing a full rebuild doesn't help.

comment:3 by zooey, 15 years ago

Resolution: fixed
Status: newclosed

Fixed in hrev31919, by using the strod()-implementation from glibc, which already lived in our repo.

Note: See TracTickets for help on using tickets.