aboutsummaryrefslogtreecommitdiffstats
path: root/lib/misc_utils/time_spec.cc
diff options
context:
space:
mode:
authorPiotr Krysik <ptrkrysik@gmail.com>2019-07-17 09:41:01 +0200
committerPiotr Krysik <ptrkrysik@gmail.com>2019-07-18 10:33:37 +0200
commit0de0172afe87f755d1f8b6c78b506c3e5369238b (patch)
treed71874bab4262d40e4eed69bf8617779f4312902 /lib/misc_utils/time_spec.cc
parent43dfbdf1a964ca4fd731e0fff523f286ecfff1f1 (diff)
utils/time_spec: support fractional tick_rate
If tick_rate is fractional rate_i variable is 0 and shouldn't be used in division. Change-Id: I660922683d837160e0546a0f339560d7d0965379
Diffstat (limited to 'lib/misc_utils/time_spec.cc')
-rw-r--r--lib/misc_utils/time_spec.cc2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/misc_utils/time_spec.cc b/lib/misc_utils/time_spec.cc
index 5293da2..7ec522e 100644
--- a/lib/misc_utils/time_spec.cc
+++ b/lib/misc_utils/time_spec.cc
@@ -59,7 +59,7 @@ namespace gr {
time_spec_t time_spec_t::from_ticks(long long ticks, double tick_rate){
const long long rate_i = (long long)(tick_rate);
const double rate_f = tick_rate - rate_i;
- const time_t secs_full = time_t(ticks/rate_i);
+ const time_t secs_full = (rate_i != 0 ? time_t(ticks/rate_i) : time_t(0));
const long long ticks_error = ticks - (secs_full*rate_i);
const double ticks_frac = ticks_error - secs_full*rate_f;
return time_spec_t(secs_full, ticks_frac/tick_rate);