5 typedef struct _LttTime
{
11 static const unsigned long NANOSECONDS_PER_SECOND
= 1000000000;
13 static const LttTime ltt_time_zero
= { 0, 0};
16 static inline LttTime
ltt_time_sub(LttTime t1
, LttTime t2
)
19 res
.tv_sec
= t1
.tv_sec
- t2
.tv_sec
;
20 if(t1
.tv_nsec
< t2
.tv_nsec
) {
22 res
.tv_nsec
= NANOSECONDS_PER_SECOND
+ t1
.tv_nsec
- t2
.tv_nsec
;
25 res
.tv_nsec
= t1
.tv_nsec
- t2
.tv_nsec
;
31 static inline LttTime
ltt_time_add(LttTime t1
, LttTime t2
)
34 res
.tv_sec
= t1
.tv_sec
+ t2
.tv_sec
;
35 res
.tv_nsec
= t1
.tv_nsec
+ t2
.tv_nsec
;
36 if(res
.tv_nsec
>= NANOSECONDS_PER_SECOND
) {
38 res
.tv_nsec
-= NANOSECONDS_PER_SECOND
;
44 static inline LttTime
ltt_time_mul(LttTime t1
, float f
)
55 sec
= t1
.tv_sec
/ (double)d
;
57 res
.tv_nsec
= t1
.tv_nsec
/ (double)d
+ (sec
- res
.tv_sec
) *
58 NANOSECONDS_PER_SECOND
;
59 res
.tv_sec
+= res
.tv_nsec
/ NANOSECONDS_PER_SECOND
;
60 res
.tv_nsec
%= NANOSECONDS_PER_SECOND
;
66 static inline LttTime
ltt_time_div(LttTime t1
, float f
)
71 sec
= t1
.tv_sec
/ (double)f
;
73 res
.tv_nsec
= t1
.tv_nsec
/ (double)f
+ (sec
- res
.tv_sec
) *
74 NANOSECONDS_PER_SECOND
;
75 res
.tv_sec
+= res
.tv_nsec
/ NANOSECONDS_PER_SECOND
;
76 res
.tv_nsec
%= NANOSECONDS_PER_SECOND
;
81 static inline int ltt_time_compare(LttTime t1
, LttTime t2
)
83 if(t1
.tv_sec
> t2
.tv_sec
) return 1;
84 if(t1
.tv_sec
< t2
.tv_sec
) return -1;
85 if(t1
.tv_nsec
> t2
.tv_nsec
) return 1;
86 if(t1
.tv_nsec
< t2
.tv_nsec
) return -1;
91 static inline double ltt_time_to_double(LttTime t1
)
93 return (double)t1
.tv_sec
+ (double)t1
.tv_nsec
/ NANOSECONDS_PER_SECOND
;
97 static inline LttTime
ltt_time_from_double(double t1
)
101 res
.tv_nsec
= (t1
- res
.tv_sec
) * NANOSECONDS_PER_SECOND
;
This page took 0.050429 seconds and 4 git commands to generate.