Skip to content

Commit

Permalink
Fix clamping function
Browse files Browse the repository at this point in the history
Clamping had an off by one error.
  • Loading branch information
pedrocr committed Nov 12, 2020
1 parent c23d8ed commit f3f25a3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/decoders/basics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ pub use crate::decoders::pumps::*;

#[inline(always)]
pub fn clampbits(val: i32, bits: u32) -> u16 {
let max = (1 << bits) - 1;
if val < 0 {
0
} else if val > (1 << bits) {
1 << bits
} else if val > max {
max as u16
} else {
val as u16
}
Expand Down

0 comments on commit f3f25a3

Please sign in to comment.