5#ifndef BITCOIN_UTIL_OVERFLOW_H
6#define BITCOIN_UTIL_OVERFLOW_H
21 if (shift == 0 || input == 0) {
25 if (shift >=
sizeof(T) * CHAR_BIT) {
29 if (input > (std::numeric_limits<T>::max() >> shift)) {
32 if (input < (std::numeric_limits<T>::min() >> shift)) {
35 return input << shift;
53 return input < 0 ? std::numeric_limits<T>::min()
54 : std::numeric_limits<T>::max();
constexpr T SaturatingLeftShift(T input, unsigned shift) noexcept
Left bit shift with safe minimum and maximum values.
constexpr std::optional< T > CheckedLeftShift(T input, unsigned shift) noexcept
Left bit shift with overflow checking.