diff options
author | Sven Gothel <[email protected]> | 2022-07-04 22:31:22 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-07-04 22:31:22 +0200 |
commit | 4076e49fa273f0808d4f85a70fb91645ed95f6d2 (patch) | |
tree | 0d9951020667dde4840c67b5ae98b17a96ffb737 /include | |
parent | fbf9047c40129c24f059fff80dafa2e15ca4ee4c (diff) |
fraction_timespec: Add sign() and abs()
Diffstat (limited to 'include')
-rw-r--r-- | include/jau/fraction_type.hpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/jau/fraction_type.hpp b/include/jau/fraction_type.hpp index bbc32f8..0f7e9d3 100644 --- a/include/jau/fraction_type.hpp +++ b/include/jau/fraction_type.hpp @@ -1034,6 +1034,28 @@ namespace jau { } /** + * Returns the value of the sign function applied to tv_sec. + * <pre> + * -1 for numerator < 0 + * 0 for numerator = 0 + * 1 for numerator > 0 + * </pre> + * @return function result + */ + constexpr snsize_t sign(const fraction_timespec& rhs) noexcept { + return sign(rhs.tv_sec); + } + + /** + * Returns the absolute fraction_timespec + */ + constexpr fraction_timespec abs(const fraction_timespec& rhs) noexcept { + fraction_timespec copy(rhs); // skip normalize + copy.tv_sec= jau::abs(rhs.tv_sec); + return copy; + } + + /** * Returns sum of two fraction_timespec. * * @param lhs a fraction_timespec |