From d0065f07cdcb62f49586e2067fd164897fddba6f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 3 Mar 2024 11:07:09 +0100 Subject: src/timer: a? --- src/timer.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/timer.cpp') diff --git a/src/timer.cpp b/src/timer.cpp index bd4baad8..b068c55d 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -46,20 +46,30 @@ uint64_t Time::init() noexcept { return get_time(); } bool Time::operator==(const Time&) const noexcept = default; std::strong_ordering Time::operator<=>(const Time&) const noexcept = default; -double Time::to_seconds(const Ns& ts) noexcept +float Time::to_seconds(const Ns& ts) noexcept { - auto x1 = double{ts}; - auto x2 = x1 * 1e-9; - fm_assert(x2 < double{1 << 24}); - return x2; + if (ts.stamp == 0) [[unlikely]] + return 0; + else + { + auto x = double(ts.stamp) * 1e-9; + fm_assert(x < double{1 << 24}); + //fm_assert(x >= 1e-10f); + return (float)x; + } } -double Time::to_milliseconds(const Ns& ts) noexcept +float Time::to_milliseconds(const Ns& ts) noexcept { - auto x1 = double{ts}; - auto x2 = x1 * 1e-6; - fm_assert(x2 < double{1 << 24}); - return x2; + if (ts.stamp == 0) [[unlikely]] + return 0; + else + { + auto x = double(ts.stamp) * 1e-6; + fm_assert(x < double{1 << 24}); + fm_assert(x >= 1e-10); + return (float)x; + } } const char* format_datetime_to_string(char (&buf)[fm_DATETIME_BUF_SIZE]) -- cgit v1.2.3