This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug manual/14450] New: timeval_subtract example is erroneous
- From: "guifo at wanadoo dot fr" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: Fri, 10 Aug 2012 15:52:02 +0000
- Subject: [Bug manual/14450] New: timeval_subtract example is erroneous
- Auto-submitted: auto-generated
http://sourceware.org/bugzilla/show_bug.cgi?id=14450
Bug #: 14450
Summary: timeval_subtract example is erroneous
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: manual
AssignedTo: unassigned@sourceware.org
ReportedBy: guifo@wanadoo.fr
CC: mtk.manpages@gmail.com, roland@gnu.org
Classification: Unclassified
Created attachment 6572
--> http://sourceware.org/bugzilla/attachment.cgi?id=6572
timeval_subtract test case
The code given as an example in manual/examples/timeval_subtract.c is giving
erroneous results when the left operand is lower than the right operand.
It was previously embedded in manual/time.texi and has been as such since its
very first appearance (in 1995 according to git log).
It is quite surprising to see how many times this code has been blindly pasted
into various projects, most of the time untouched (a quick Google search shows
this).
Let's hope this has been made each time with due care...
The attached test_timeval_subtract.c source file exposes the error. This file
contains a copy of the function found in manual/examples/timeval_subtract.c
plus a new function with a proposed correction.
$ gcc -o test_timeval_subtract test_timeval_subtract.c
$ ./test_timeval_subtract
Current timeval_subtract
1.500000 - 10.499998 => -9.000002 returned sign: -
1.500000 - 10.499999 => -9.000001 returned sign: -
1.500000 - 10.500000 => -9.000000 returned sign: -
1.500000 - 10.500001 => -10.999999 returned sign: -
1.500000 - 10.500002 => -10.999998 returned sign: -
New timeval_subtract
1.500000 - 10.499998 => 8.999998 returned sign: -
1.500000 - 10.499999 => 8.999999 returned sign: -
1.500000 - 10.500000 => 9.000000 returned sign: -
1.500000 - 10.500001 => 9.000001 returned sign: -
1.500000 - 10.500002 => 9.000002 returned sign: -
Values in the first block are obviously wrong, even showing a discontinuity,
while in the second block values computed with the corrected function are the
expected ones.
A patch to apply the proposed correction on manual/examples/timeval_subtract.c
will be attached.
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.