MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / difftime

Function difftime

datetime/difftime.c:16–65  ·  view source on GitHub ↗
(time1, time0)

Source from the content-addressed store, hash-verified

14#include "private.h" /* for time_t, TYPE_INTEGRAL, and TYPE_SIGNED */
15
16double
17difftime(time1, time0)
18const time_t time1;
19const time_t time0;
20{
21 /*
22 ** If (sizeof (double) > sizeof (time_t)) simply convert and subtract
23 ** (assuming that the larger type has more precision).
24 ** This is the common real-world case circa 2004.
25 */
26 if (sizeof (double) > sizeof (time_t))
27 return (double) time1 - (double) time0;
28 if (!TYPE_INTEGRAL(time_t)) {
29 /*
30 ** time_t is floating.
31 */
32 return time1 - time0;
33 }
34 if (!TYPE_SIGNED(time_t)) {
35 /*
36 ** time_t is integral and unsigned.
37 ** The difference of two unsigned values can't overflow
38 ** if the minuend is greater than or equal to the subtrahend.
39 */
40 if (time1 >= time0)
41 return time1 - time0;
42 else return -((double) (time0 - time1));
43 }
44 /*
45 ** time_t is integral and signed.
46 ** Handle cases where both time1 and time0 have the same sign
47 ** (meaning that their difference cannot overflow).
48 */
49 if ((time1 < 0) == (time0 < 0))
50 return time1 - time0;
51 /*
52 ** time1 and time0 have opposite signs.
53 ** Punt if unsigned long is too narrow.
54 */
55 if (sizeof (unsigned long) < sizeof (time_t))
56 return (double) time1 - (double) time0;
57 /*
58 ** Stay calm...decent optimizers will eliminate the complexity below.
59 */
60 if (time1 >= 0 /* && time0 < 0 */)
61 return (unsigned long) time1 +
62 (unsigned long) (-(time0 + 1)) + 1;
63 return -(double) ((unsigned long) time0 +
64 (unsigned long) (-(time1 + 1)) + 1);
65}

Callers 7

sql_trickle_intFunction · 0.85
sql_heartbeat_cbFunction · 0.85
trigger_register_intFunction · 0.85
trigger_statFunction · 0.85
watchdog_threadFunction · 0.85
stop_waitingFunction · 0.85
os_difftimeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected