fix shift_round overflow error

This commit is contained in:
Matt Huszagh 2021-01-14 14:41:51 -08:00
parent d1aa2f04c4
commit 9f0b3eb77e

View File

@ -17,7 +17,7 @@ pub type Complex<T> = (T, T);
/// Shifted and rounded value.
#[inline(always)]
pub fn shift_round(x: i32, shift: usize) -> i32 {
(x + (1 << (shift - 1))) >> shift
x.saturating_add(1 << (shift - 1)) >> shift
}
/// Integer division, round up half.