From ccsanady@friley216.res.iastate.edu  Thu Nov 14 04:41:29 1996
Received: from friley216.res.iastate.edu (friley216.res.iastate.edu [129.186.78.216])
          by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id EAA06308
          for <FreeBSD-gnats-submit@freebsd.org>; Thu, 14 Nov 1996 04:41:28 -0800 (PST)
Received: (from ccsanady@localhost) by friley216.res.iastate.edu (8.7.6/8.7.3) id GAA01965; Thu, 14 Nov 1996 06:41:25 -0600 (CST)
Message-Id: <199611141241.GAA01965@friley216.res.iastate.edu>
Date: Thu, 14 Nov 1996 06:41:25 -0600 (CST)
From: Chris Csanady <ccsanady@friley216.res.iastate.edu>
Reply-To: ccsanady@friley216.res.iastate.edu
To: FreeBSD-gnats-submit@freebsd.org
Subject: /usr/include/sys lacking timer arithmetic functions..
X-Send-Pr-Version: 3.2

>Number:         2007
>Category:       misc
>Synopsis:       /usr/include/sys lacking timer arithmetic functions..
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 14 04:50:00 PST 1996
>Closed-Date:    Sun Nov 17 12:23:59 PST 1996
>Last-Modified:  Sun Nov 17 12:28:28 PST 1996
>Originator:     Chris Csanady
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
>Environment:

	

>Description:

	

It would be nice if there were more timer arithmetic functions in sys/time.h.
The following is a patch from the relevent portion which I have taken from
NetBSD's.

>How-To-Repeat:

	

>Fix:
	
	

--- time.h.new	Thu Nov 14 06:30:41 1996
***************
*** 84,89 ****
--- 84,107 ----
  	(((tvp)->tv_sec == (uvp)->tv_sec) ?				\
  	    ((tvp)->tv_usec cmp (uvp)->tv_usec) :			\
  	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
+ #define timeradd(tvp, uvp, vvp)						\
+ 	do {								\
+ 		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
+ 		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
+ 		if ((vvp)->tv_usec >= 1000000) {			\
+ 			(vvp)->tv_sec++;				\
+ 			(vvp)->tv_usec -= 1000000;			\
+ 		}							\
+ 	} while (0)
+ #define timersub(tvp, uvp, vvp)						\
+         do {								\
+ 		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
+ 		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
+ 		if ((vvp)->tv_usec < 0) {				\
+ 			(vvp)->tv_sec--;				\
+ 			(vvp)->tv_usec += 1000000;			\
+ 		}							\
+ 	} while (0)
  
  /*
   * Names of the interval timers, and structure
>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: ccsanady@friley216.res.iastate.edu, FreeBSD-gnats-submit@FreeBSD.org
Cc:  Subject: Re: misc/2007: /usr/include/sys lacking timer arithmetic functions..
Date: Fri, 15 Nov 1996 01:23:00 +1100

 >It would be nice if there were more timer arithmetic functions in sys/time.h.
 >The following is a patch from the relevent portion which I have taken from
 >NetBSD's.
 
 s/nice/nasty/
 
 Applications got along for years without these functions, so why add them
 now that floating point is faster than timeval arithmetic on most machines,
 64-bit machines are becoming available, and 64 bit long longs are available?
 I usually use the following timeval arithmetic functions:
 
 	timeval difference -> double
 		((tv2.tv_sec - tv1.tv_sec) + (tv2.tv_usec - tv1.tv_sec) * 1e-6)
 	timeval -> double
 		(tv1.tv_sec + tv1.tv_sec * 1e-6)
 
 Why not add these, and more functions for 64 bit longs, and more for 64 bit
 long longs...?  Pretty soon you'll need C++ to manage them all :-).
 
 Bruce
State-Changed-From-To: open->closed 
State-Changed-By: bde 
State-Changed-When: Sun Nov 17 12:23:59 PST 1996 
State-Changed-Why:  
The change is not necessary.  The macros are to avoid duplicating 
code in the kernel in NetBSD, but FreeBSD already avoids duplication 
by using functions and not attempting to optimize this. 
>Unformatted:
