From a24993993ca2bd78403853a39d816b1125736ca0 Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Mon, 25 Aug 2025 10:23:56 -0700 Subject: [PATCH] Hide our custom fabs() function Signed-off-by: Darby Johnston --- src/opentime/rationalTime.h | 32 +++++++++++++++++--------------- src/opentime/timeRange.h | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/opentime/rationalTime.h b/src/opentime/rationalTime.h index ef10fec67..3d8177957 100644 --- a/src/opentime/rationalTime.h +++ b/src/opentime/rationalTime.h @@ -20,21 +20,6 @@ enum IsDropFrameRate : int ForceYes = 1, }; -/// @brief Returns the absolute value. -/// -/// \todo Document why this function is used instead of "std::fabs()". -constexpr double -fabs(double val) noexcept -{ - union - { - double f; - uint64_t i; - } bits = { val }; - bits.i &= std::numeric_limits::max() / 2; - return bits.f; -} - /// @brief This class represents a measure of time defined by a value and rate. class RationalTime { @@ -419,6 +404,23 @@ class RationalTime friend class TimeRange; double _value, _rate; + + /// @brief Returns the absolute value. + /// + /// \todo This function is used instead of "std::fabs()" so we can mark it as + /// constexpr. We can remove this and replace it with the std version when we + /// upgrade to C++23. Note that there are two copies of this function, in both + /// RationalTime and TimeRange. + static constexpr double fabs(double val) noexcept + { + union + { + double f; + uint64_t i; + } bits = { val }; + bits.i &= std::numeric_limits::max() / 2; + return bits.f; + } }; }} // namespace opentime::OPENTIME_VERSION diff --git a/src/opentime/timeRange.h b/src/opentime/timeRange.h index 747607a52..f670ca11a 100644 --- a/src/opentime/timeRange.h +++ b/src/opentime/timeRange.h @@ -441,6 +441,23 @@ class TimeRange { return rhs - lhs >= epsilon; } + + /// @brief Returns the absolute value. + /// + /// \todo This function is used instead of "std::fabs()" so we can mark it as + /// constexpr. We can remove this and replace it with the std version when we + /// upgrade to C++23. Note that there are two copies of this function, in both + /// RationalTime and TimeRange. + static constexpr double fabs(double val) noexcept + { + union + { + double f; + uint64_t i; + } bits = { val }; + bits.i &= std::numeric_limits::max() / 2; + return bits.f; + } }; }} // namespace opentime::OPENTIME_VERSION