diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-02 11:52:53 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-02 11:52:53 +0100 |
| commit | a6481a7065852cb01846a5dc8a92fd415ba745fb (patch) | |
| tree | 68321663f06ca3d3b54774e6a649283ef944df81 /src/timer-ns.cpp | |
| parent | 9ff017f1d4c1502fca9797aa4b38351c97e57982 (diff) | |
w
Diffstat (limited to 'src/timer-ns.cpp')
| -rw-r--r-- | src/timer-ns.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/timer-ns.cpp b/src/timer-ns.cpp index a6d1a073..45d0411c 100644 --- a/src/timer-ns.cpp +++ b/src/timer-ns.cpp @@ -56,6 +56,14 @@ Ns operator*(uint64_t a, const Ns& rhs) return Ns{a} * b; } +Ns operator*(const Ns& lhs, float b_) +{ + long double a(lhs.stamp), b(b_); + auto x = a * b; + fm_assert(x <= 1 << 24 && x >= 0); + return Ns{uint64_t(x)}; +} + uint64_t operator/(const Ns& lhs, const Ns& rhs) { auto a = lhs.stamp, b = rhs.stamp; @@ -96,6 +104,14 @@ std::strong_ordering operator<=>(const Ns& lhs, const Ns& rhs) return a <=> b; } +Ns Ns::from_millis(uint64_t a) +{ + constexpr auto b = uint64_t(1e6); + const auto x = a * b; + fm_assert(a == 0 || x / a == b); + return Ns{x}; +}; + Ns::operator uint64_t() const { return stamp; } Ns::operator float() const { return float(stamp); } uint64_t Ns::operator*() const { return stamp; } |
