public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug manual/14450] New: timeval_subtract example is erroneous
@ 2012-08-10 15:52 guifo at wanadoo dot fr
  2012-08-10 15:55 ` [Bug manual/14450] " guifo at wanadoo dot fr
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: guifo at wanadoo dot fr @ 2012-08-10 15:52 UTC (permalink / raw)
  To: glibc-bugs

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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug manual/14450] timeval_subtract example is erroneous
  2012-08-10 15:52 [Bug manual/14450] New: timeval_subtract example is erroneous guifo at wanadoo dot fr
@ 2012-08-10 15:55 ` guifo at wanadoo dot fr
  2012-12-11  3:11 ` siddhesh at redhat dot com
  2014-06-17 18:47 ` fweimer at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: guifo at wanadoo dot fr @ 2012-08-10 15:55 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14450

--- Comment #1 from Guillaume Foliard <guifo at wanadoo dot fr> 2012-08-10 15:54:48 UTC ---
Created attachment 6573
  --> http://sourceware.org/bugzilla/attachment.cgi?id=6573
Proposed correction

-- 
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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug manual/14450] timeval_subtract example is erroneous
  2012-08-10 15:52 [Bug manual/14450] New: timeval_subtract example is erroneous guifo at wanadoo dot fr
  2012-08-10 15:55 ` [Bug manual/14450] " guifo at wanadoo dot fr
@ 2012-12-11  3:11 ` siddhesh at redhat dot com
  2014-06-17 18:47 ` fweimer at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: siddhesh at redhat dot com @ 2012-12-11  3:11 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14450

Siddhesh Poyarekar <siddhesh at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |siddhesh at redhat dot com
         Resolution|                            |INVALID

--- Comment #2 from Siddhesh Poyarekar <siddhesh at redhat dot com> 2012-12-11 03:11:17 UTC ---
Not really.  timeval is not simply tv_sec.tv_usec.  It is tv_sec + tv_usec /
1000000.  They have different semantics when tv_sec is negative.  So you read:

{-10, 999999}

as

-10 + 999999/1000000 = -9.000001

and not

-10.999999

-- 
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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug manual/14450] timeval_subtract example is erroneous
  2012-08-10 15:52 [Bug manual/14450] New: timeval_subtract example is erroneous guifo at wanadoo dot fr
  2012-08-10 15:55 ` [Bug manual/14450] " guifo at wanadoo dot fr
  2012-12-11  3:11 ` siddhesh at redhat dot com
@ 2014-06-17 18:47 ` fweimer at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: fweimer at redhat dot com @ 2014-06-17 18:47 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=14450

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-06-17 18:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-10 15:52 [Bug manual/14450] New: timeval_subtract example is erroneous guifo at wanadoo dot fr
2012-08-10 15:55 ` [Bug manual/14450] " guifo at wanadoo dot fr
2012-12-11  3:11 ` siddhesh at redhat dot com
2014-06-17 18:47 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).