Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ where
{
pub fn new(precision: u32) -> Self {
let low = B::ZERO;
let high = B::ONE << precision;
let high = (B::ONE << precision) - B::ONE;

Self {
precision,
Expand Down
6 changes: 3 additions & 3 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ where
fn normalise(&mut self) -> io::Result<()> {
while self.state.high < self.state.half() || self.state.low >= self.state.half() {
if self.state.high < self.state.half() {
self.state.high <<= 1;
self.state.high = (self.state.high << 1) + B::ONE;
self.state.low <<= 1;
self.x <<= 1;
} else {
// self.low >= self.half()
self.state.low = (self.state.low - self.state.half()) << 1;
self.state.high = (self.state.high - self.state.half()) << 1;
self.state.high = ((self.state.high - self.state.half()) << 1) + B::ONE;
self.x = (self.x - self.state.half()) << 1;
}

Expand All @@ -228,7 +228,7 @@ where
&& self.state.high < (self.state.three_quarter())
{
self.state.low = (self.state.low - self.state.quarter()) << 1;
self.state.high = (self.state.high - self.state.quarter()) << 1;
self.state.high = ((self.state.high - self.state.quarter()) << 1) + B::ONE;
self.x = (self.x - self.state.quarter()) << 1;

if self.input.next_bit()? == Some(true) {
Expand Down
6 changes: 3 additions & 3 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ where
while self.state.high < self.state.half() || self.state.low >= self.state.half() {
if self.state.high < self.state.half() {
self.emit(false)?;
self.state.high <<= 1;
self.state.high = (self.state.high << 1) + B::ONE;
self.state.low <<= 1;
} else {
self.emit(true)?;
self.state.low = (self.state.low - self.state.half()) << 1;
self.state.high = (self.state.high - self.state.half()) << 1;
self.state.high = ((self.state.high - self.state.half()) << 1) + B::ONE;
}
}

Expand All @@ -215,7 +215,7 @@ where
{
self.pending += 1;
self.state.low = (self.state.low - self.state.quarter()) << 1;
self.state.high = (self.state.high - self.state.quarter()) << 1;
self.state.high = ((self.state.high - self.state.quarter()) << 1) + B::ONE;
}

Ok(())
Expand Down
Loading