bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

c-ldtoastr test failure


From: Bruno Haible
Subject: c-ldtoastr test failure
Date: Mon, 10 Aug 2020 08:55:11 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-186-generic; KDE/5.18.0; x86_64; ; )

Hi Marc,

On a Linux/x86_64 system, the c-ldtoastr uni test fails.

How to reproduce:
$ ./gnulib-tool --test --single-configure c-ldtoastr

The test fails like this:
../../gltests/test-c-ldtoastr.c:54: assertion '!strcmp (buf, "0.1")' failed

In the debugger, I see that where the code expects a result "0.1",
the actual result is "0.10000000000000000555".

This rounding error is not caused by the library code for binary to decimal
conversion, because you can see that the number in its full glory in the
debugger:

(gdb) step
c_ldtoastr (buf=buf@entry=0x7fffffffd670 "1,", bufsize=bufsize@entry=40, 
flags=flags@entry=0, width=width@entry=0, 
    x=0.1000000000000000055511151231257827) at ../../gllib/ftoastr.c:113


Here's a suggested fix. OK to push?


2020-08-09  Bruno Haible  <bruno@clisp.org>

        c-ldtoastr tests: Fix test failure.
        * tests/test-c-ldtoastr.c (main): Support platforms where 'long double'
        is longer than 'double'.

diff --git a/tests/test-c-ldtoastr.c b/tests/test-c-ldtoastr.c
index 140f0c6..7e38422 100644
--- a/tests/test-c-ldtoastr.c
+++ b/tests/test-c-ldtoastr.c
@@ -50,7 +50,7 @@ main (int argc, char *argv[])
   {
     char buf[DBL_BUFSIZE_BOUND];
 
-    c_ldtoastr (buf, sizeof buf, 0, 0, 0.1);
+    c_ldtoastr (buf, sizeof buf, 0, 0, 0.1L);
     ASSERT (!strcmp (buf, "0.1"));
   }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]