From 9f0b3eb77edff8d5080b5ccae91d2db606342a95 Mon Sep 17 00:00:00 2001 From: Matt Huszagh Date: Thu, 14 Jan 2021 14:41:51 -0800 Subject: [PATCH] fix shift_round overflow error --- dsp/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsp/src/lib.rs b/dsp/src/lib.rs index 77d8bc1..6f521f1 100644 --- a/dsp/src/lib.rs +++ b/dsp/src/lib.rs @@ -17,7 +17,7 @@ pub type Complex = (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.