Go to the documentation of this file.00001
00005 #include <blort/Recognizer3D/Math.hh>
00006
00007
00008 namespace P
00009 {
00010
00011
00016 int timeval_subtract(struct timeval *result, struct timeval *x,
00017 struct timeval *y)
00018 {
00019 if(x->tv_usec < y->tv_usec)
00020 {
00021 int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
00022 y->tv_usec -= 1000000 * nsec;
00023 y->tv_sec += nsec;
00024 }
00025 if(x->tv_usec - y->tv_usec > 1000000)
00026 {
00027 int nsec = (y->tv_usec - x->tv_usec) / 1000000;
00028 y->tv_usec += 1000000 * nsec;
00029 y->tv_sec -= nsec;
00030 }
00031 result->tv_sec = x->tv_sec - y->tv_sec;
00032 result->tv_usec = x->tv_usec - y->tv_usec;
00033 return x->tv_sec < y->tv_sec;
00034 }
00035
00039 double timespec_diff(struct timespec *x, struct timespec *y)
00040 {
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 if(x->tv_nsec < y->tv_nsec)
00056 {
00057 int nsec = (y->tv_nsec - x->tv_nsec) / 1000000000 + 1;
00058 y->tv_nsec -= 1000000000 * nsec;
00059 y->tv_sec += nsec;
00060 }
00061 if(x->tv_nsec - y->tv_nsec > 1000000000)
00062 {
00063 int nsec = (y->tv_nsec - x->tv_nsec) / 1000000000;
00064 y->tv_nsec += 1000000000 * nsec;
00065 y->tv_sec -= nsec;
00066 }
00067 return (double)(x->tv_sec - y->tv_sec) +
00068 (double)(x->tv_nsec - y->tv_nsec)/1000000000.;
00069 }
00070
00071
00072
00073 }
00074