3 * Copyright 2007,2008 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <gnuradio/omni_time.h>
26 #include <gnuradio/omnithread.h>
31 omni_time::omni_time(double real_secs)
33 double floor_secs = floor(real_secs);
34 d_secs = (long) floor_secs;
35 d_nsecs = (long) ((real_secs - floor_secs) * 1e9); // always positive
39 omni_time::time(const omni_time &delta_t)
41 unsigned long abs_sec, abs_nsec;
42 unsigned long rel_sec = delta_t.d_secs;
43 unsigned long rel_nsec = delta_t.d_nsecs;
45 omni_thread::get_time(&abs_sec, &abs_nsec, rel_sec, rel_nsec);
46 return omni_time(abs_sec, abs_nsec);
51 operator+(const omni_time &x, const omni_time &y)
53 omni_time r(x.d_secs + y.d_secs, x.d_nsecs + y.d_nsecs);
54 while (r.d_nsecs >= 1000000000){
55 r.d_nsecs -= 1000000000;
62 operator-(const omni_time &x, const omni_time &y)
66 omni_time r(x.d_secs - y.d_secs, x.d_nsecs - y.d_nsecs);
67 while (r.d_nsecs < 0){
68 r.d_nsecs += 1000000000;
75 operator+(const omni_time &x, double y)
77 return x + omni_time(y);
81 operator-(const omni_time &x, double y)
83 return x - omni_time(y);