Skip to content

Commit

Permalink
Replaced some floating point code with integer calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
cry-inc committed Mar 2, 2024
1 parent 1ecdb01 commit 4d84f93
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/bs_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl ByteStreamReadBuffer {
}

let start_offset = self.offset / 8;
let end_offset = ((self.offset + bits) as f32 / 8.).ceil() as usize;
let end_offset = (self.offset + bits + 7) / 8; // Integer division with rounding up
let offset = self.offset % 8;

let mut data = [0; 16];
Expand Down
2 changes: 1 addition & 1 deletion src/bs_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl ByteStreamWriteBuffer {

pub fn add_bits(&mut self, data: &[u8], bits: usize) {
if self.last_byte_bit == 0 {
let to_append = (bits as f32 / 8.0).ceil() as usize;
let to_append = (bits + 7) / 8; // Integer division with rounding up
self.buffer.extend_from_slice(&data[..to_append]);
self.last_byte_bit = bits % 8;
} else {
Expand Down

0 comments on commit 4d84f93

Please sign in to comment.