From ffc5b93f95850bd753c33009f0457aa11197f498 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 1 Mar 2018 18:12:25 +0000 Subject: [PATCH] tmv: Add tmv_sign() The sign of time values is tested in tsproc.c. Add an abstraction tmv_sign() to return the sign of a time value. Signed-off-by: Michael Brown --- tmv.h | 5 +++++ tsproc.c | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tmv.h b/tmv.h index 5717846..eff172f 100644 --- a/tmv.h +++ b/tmv.h @@ -56,6 +56,11 @@ static inline int tmv_cmp(tmv_t a, tmv_t b) return a == b ? 0 : a > b ? +1 : -1; } +static inline int tmv_sign(tmv_t x) +{ + return x == 0 ? 0 : x > 0 ? +1 : -1; +} + static inline int tmv_is_zero(tmv_t x) { return x == ((tmv_t) 0) ? 1 : 0; diff --git a/tsproc.c b/tsproc.c index 91bae37..a871049 100644 --- a/tsproc.c +++ b/tsproc.c @@ -133,7 +133,7 @@ tmv_t get_raw_delay(struct tsproc *tsp) t41 = tmv_sub(tsp->t4, tsp->t1); delay = tmv_div(tmv_add(t23, t41), 2); - if (delay < 0) { + if (tmv_sign(delay) < 0) { pr_debug("negative delay %10" PRId64, tmv_to_nanoseconds(delay)); pr_debug("delay = (t2 - t3) * rr + (t4 - t1)"); @@ -215,7 +215,8 @@ int tsproc_update_offset(struct tsproc *tsp, tmv_t *offset, double *weight) if (!weight) return 0; - if (weighting(tsp) && tsp->filtered_delay > 0 && raw_delay > 0) { + if (weighting(tsp) && tmv_sign(tsp->filtered_delay) > 0 && + tmv_sign(raw_delay) > 0) { *weight = tmv_dbl(tsp->filtered_delay) / tmv_dbl(raw_delay); if (*weight > 1.0) *weight = 1.0;