Skip to content

Commit

Permalink
Fix operator/(duration, duration) return type
Browse files Browse the repository at this point in the history
Dividing two durations shall yield a dimensionless number and not a
duration.

Fixes #554.
  • Loading branch information
mtnpke committed Jan 28, 2025
1 parent 1e83906 commit 99da32e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/EASTL/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ namespace chrono
}

template <typename Rep1, typename Period1, typename Rep2, typename Period2>
typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type EASTL_FORCE_INLINE
typename eastl::common_type<Rep1, Rep2>::type EASTL_FORCE_INLINE
operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
{
typedef typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type common_duration_t;
return common_duration_t(common_duration_t(lhs).count() / common_duration_t(rhs).count());
return common_duration_t(lhs).count() / common_duration_t(rhs).count();
}

template <typename Rep1, typename Period1, typename Rep2>
Expand Down
7 changes: 7 additions & 0 deletions test/source/TestChrono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ int TestDuration()
}
}

{
seconds s(5);
milliseconds ms(10);
VERIFY(s / ms == 500);
VERIFY(ms / s.count() == milliseconds(2));
}

return nErrorCount;
}

Expand Down

0 comments on commit 99da32e

Please sign in to comment.