NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/44741: strtod convert 0.010000000000000000057612911342378542997169 incorrectly
>Number: 44741
>Category: lib
>Synopsis: strtod convert 0.010000000000000000057612911342378542997169
>incorrectly
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Mar 19 00:25:01 +0000 2011
>Originator: Alexander Nasonov
>Release: NetBSD 5.99.48 amd64
>Organization:
home sweet home
>Environment:
NetBSD nebeda.localdomain 5.99.48 NetBSD 5.99.48 (GENERIC) #0: Wed Mar 16
22:33:54 GMT 2011
root@nebeda.localdomain:/home/alnsn/src/netbsd-current/src/sys/arch/amd64/compile/obj/GENERIC
amd64
>Description:
See the entry "Fri Nov 5 13:02:41 MDT 2010" from
http://www.netlib.org/fp/changes
Fri Nov 5 13:02:41 MDT 2010
dtoa.c: fix a bug related to bigcomp: decimal strings with all
zeros before the decimal point more than 40 significant digits that
required use of bigcomp might be converted very incorrectly.
Example: .010000000000000000057612911342378542997169 .
Thanks to Rick Regan <exploringbinary%gmail.com@localhost> for reporting the
symptoms and providing an example.
>How-To-Repeat:
Apply the patch to tests/lib/libc/stdlib/t_strtox.c abd run the test.
$ ./t_strtox bug20101105
*** Check failed:
/home/alnsn/src/netbsd-current/src/tests/lib/libc/stdlib/t_strtox.c:82: buf !=
str (0.010000000000000000208166817117216851329431 !=
0.010000000000000000057612911342378542997169)
failed: 1 checks failed; see output for more details
I don't know whether netbsd guarantees that string->double->string
conversion returns original value so feel free to change
ATF_CHECK_STREQ check to a more correct check.
$ cvs diff -u tests/lib/libc/stdlib/t_strtox.c
Index: tests/lib/libc/stdlib/t_strtox.c
===================================================================
RCS file: /cvsroot/src/tests/lib/libc/stdlib/t_strtox.c,v
retrieving revision 1.2
diff -u -u -r1.2 t_strtox.c
--- tests/lib/libc/stdlib/t_strtox.c 6 Dec 2010 17:30:07 -0000 1.2
+++ tests/lib/libc/stdlib/t_strtox.c 19 Mar 2011 00:01:51 -0000
@@ -32,7 +32,9 @@
__RCSID("$NetBSD: t_strtox.c,v 1.2 2010/12/06 17:30:07 pooka Exp $");
#include <atf-c.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
ATF_TC(hexadecimal);
@@ -56,9 +58,34 @@
atf_tc_expect_pass();
}
+ATF_TC(bug20101105);
+
+ATF_TC_HEAD(bug20101105, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test strtod(\"0.010000000000000000057612911342378542997169\",
NULL)");
+}
+
+ATF_TC_BODY(bug20101105, tc)
+{
+ const char str[] = "0.010000000000000000057612911342378542997169";
+ const int digits = sizeof(str) - sizeof("0."); /* precision for %.*f */
+
+ int n;
+ char buf[sizeof(str)];
+
+ double val = strtod(str, NULL);
+
+ n = snprintf(buf, sizeof(buf), "%.*f", digits, val);
+ ATF_REQUIRE(n + 1 == sizeof(buf));
+
+ ATF_CHECK_STREQ(buf, str);
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, hexadecimal);
+ ATF_TP_ADD_TC(tp, bug20101105);
return atf_no_error();
}
>Fix:
Home |
Main Index |
Thread Index |
Old Index