Bug 1039924 part 7 - Add unary minus operator to BaseTimeDuration; r=froydnj

This patch adds the unary minus operator so, for example, we can write:

  TimeDuration sinceBeforeYourSunBurnedHot = -TimeDuration::Forever();
This commit is contained in:
Brian Birtles 2014-09-25 14:25:50 +09:00
Родитель 9f07908ee4
Коммит 2268355a2b
1 изменённых файлов: 15 добавлений и 0 удалений

Просмотреть файл

@ -160,6 +160,21 @@ public:
mValue = ValueCalculator::Subtract(mValue, aOther.mValue);
return *this;
}
BaseTimeDuration operator-() const
{
// We don't just use FromTicks(ValueCalculator::Subtract(0, mValue))
// since that won't give the correct result for -TimeDuration::Forever().
int64_t ticks;
if (mValue == INT64_MAX) {
ticks = INT64_MIN;
} else if (mValue == INT64_MIN) {
ticks = INT64_MAX;
} else {
ticks = -mValue;
}
return FromTicks(ticks);
}
private:
// Block double multiplier (slower, imprecise if long duration) - Bug 853398.