1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-05 22:14:55 +00:00

AK: Expose Checked::saturating_[add|sub] as static helpers

This commit is contained in:
Hendiadyoin1 2023-07-26 14:53:21 +02:00 committed by Alexander Kalenik
parent af161a8b83
commit 127b966219

View File

@ -338,6 +338,22 @@ public:
#endif
}
template<typename U, typename V>
static constexpr T saturating_add(U a, V b)
{
Checked checked { a };
checked.saturating_add(b);
return checked.value();
}
template<typename U, typename V>
static constexpr T saturating_sub(U a, V b)
{
Checked checked { a };
checked.saturating_sub(b);
return checked.value();
}
template<typename U, typename V>
[[nodiscard]] static constexpr bool multiplication_would_overflow(U u, V v)
{