Add unary operator- to units
This will be used in the frame buffer 3 scheduler. Bug: webrtc:13343 Change-Id: Ib699072021da30022a34aabe24e36a37e89ddf41 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/245642 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35658}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
3fd9cbc7a0
commit
21e97f9b9d
1
BUILD.gn
1
BUILD.gn
@ -562,6 +562,7 @@ if (rtc_include_tests && !build_with_chromium) {
|
||||
"rtc_base/task_utils:pending_task_safety_flag_unittests",
|
||||
"rtc_base/task_utils:repeating_task_unittests",
|
||||
"rtc_base/task_utils:to_queued_task_unittests",
|
||||
"rtc_base/units:units_unittests",
|
||||
"sdk:sdk_tests",
|
||||
"test:rtp_test_utils",
|
||||
"test:test_main",
|
||||
|
||||
@ -298,6 +298,14 @@ template <class Unit_T>
|
||||
inline constexpr Unit_T operator*(int32_t scalar, RelativeUnit<Unit_T> other) {
|
||||
return other * scalar;
|
||||
}
|
||||
template <class Unit_T>
|
||||
inline constexpr Unit_T operator-(RelativeUnit<Unit_T> other) {
|
||||
if (other.IsPlusInfinity())
|
||||
return UnitBase<Unit_T>::MinusInfinity();
|
||||
if (other.IsMinusInfinity())
|
||||
return UnitBase<Unit_T>::PlusInfinity();
|
||||
return -1 * other;
|
||||
}
|
||||
|
||||
} // namespace rtc_units_impl
|
||||
|
||||
|
||||
@ -231,5 +231,16 @@ TEST(UnitBaseTest, InfinityOperations) {
|
||||
EXPECT_TRUE((finite + TestUnit::MinusInfinity()).IsMinusInfinity());
|
||||
EXPECT_TRUE((finite - TestUnit::PlusInfinity()).IsMinusInfinity());
|
||||
}
|
||||
|
||||
TEST(UnitBaseTest, UnaryMinus) {
|
||||
const int64_t kValue = 1337;
|
||||
const TestUnit unit = TestUnit::FromValue(kValue);
|
||||
EXPECT_EQ(-unit.ToValue(), -kValue);
|
||||
|
||||
// Check infinity.
|
||||
EXPECT_EQ(-TestUnit::PlusInfinity(), TestUnit::MinusInfinity());
|
||||
EXPECT_EQ(-TestUnit::MinusInfinity(), TestUnit::PlusInfinity());
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user