From 4939bc2f59eaca21400ef291e47d24e7dfa6d7f5 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 12 Apr 2022 16:21:02 -0500 Subject: [PATCH] a/util: Manual fixes to clang-tidy issues. --- src/xrt/auxiliary/util/u_frame_times_widget.h | 4 ++-- src/xrt/auxiliary/util/u_time.h | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/xrt/auxiliary/util/u_frame_times_widget.h b/src/xrt/auxiliary/util/u_frame_times_widget.h index 123e95606..922580852 100644 --- a/src/xrt/auxiliary/util/u_frame_times_widget.h +++ b/src/xrt/auxiliary/util/u_frame_times_widget.h @@ -52,7 +52,7 @@ u_frame_times_widget_push_sample(struct u_frame_times_widget *widget, uint64_t n for (int i = 0; i < NUM_FRAME_TIMINGS; i++) { uint64_t frametime_ns = widget->times_ns[i + 1] - widget->times_ns[i]; - float frametime_s = frametime_ns * 1.f / 1000.f * 1.f / 1000.f * 1.f / 1000.f; + float frametime_s = (float)time_ns_to_s(frametime_ns); total_s += frametime_s; } float avg_frametime_s = total_s / ((float)NUM_FRAME_TIMINGS); @@ -62,7 +62,7 @@ u_frame_times_widget_push_sample(struct u_frame_times_widget *widget, uint64_t n widget->times_ns[widget->index] = new_frame_time; uint64_t diff = widget->times_ns[widget->index] - widget->times_ns[last_index]; - widget->timings_ms[widget->index] = (float)diff * 1.f / 1000.f * 1.f / 1000.f; + widget->timings_ms[widget->index] = (float)time_ns_to_ms_f(diff); } static inline void diff --git a/src/xrt/auxiliary/util/u_time.h b/src/xrt/auxiliary/util/u_time.h index e5abb5ac9..4d62fd7c3 100644 --- a/src/xrt/auxiliary/util/u_time.h +++ b/src/xrt/auxiliary/util/u_time.h @@ -25,7 +25,7 @@ extern "C" { #endif //! Helper define to make code more readable. -#define U_1_000_000_000 (1000000000) +#define U_1_000_000_000 (1000 * 1000 * 1000) /*! * The number of nanoseconds in a second. @@ -36,18 +36,18 @@ extern "C" { #define U_TIME_1S_IN_NS U_1_000_000_000 /*! - * The number of nanoseconds in a milliseconds. + * The number of nanoseconds in a millisecond. * * @see timepoint_ns */ -#define U_TIME_1MS_IN_NS (U_TIME_1S_IN_NS / 1000) +#define U_TIME_1MS_IN_NS (1000 * 1000) /*! - * The number of nanoseconds in half a milliseconds. + * The number of nanoseconds in half a millisecond. * * @see timepoint_ns */ -#define U_TIME_HALF_MS_IN_NS (U_TIME_1MS_IN_NS / 2) +#define U_TIME_HALF_MS_IN_NS (U_TIME_1MS_IN_NS / 2.0) /*! * Integer timestamp type. @@ -78,7 +78,7 @@ typedef int64_t time_duration_ns; static inline double time_ns_to_s(time_duration_ns ns) { - return (double)(ns) / (double)U_TIME_1S_IN_NS; + return (double)(ns) / (double)(U_TIME_1S_IN_NS); } /*! @@ -102,7 +102,7 @@ time_s_to_ns(double duration) static inline double time_ns_to_ms_f(time_duration_ns ns) { - return (double)(ns) / (double)U_TIME_1MS_IN_NS; + return (double)(ns) / (double)(U_TIME_1MS_IN_NS); } /*!