Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/opentime/rationalTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>::max() / 2;
return bits.f;
}

/// @brief This class represents a measure of time defined by a value and rate.
class RationalTime
{
Expand Down Expand Up @@ -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<uint64_t>::max() / 2;
return bits.f;
}
};

}} // namespace opentime::OPENTIME_VERSION
17 changes: 17 additions & 0 deletions src/opentime/timeRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>::max() / 2;
return bits.f;
}
};

}} // namespace opentime::OPENTIME_VERSION
Loading