Skip to content

Commit

Permalink
Revert "simplify round"
Browse files Browse the repository at this point in the history
This reverts commit 18a9b67.
  • Loading branch information
hasindu2008 committed Oct 3, 2024
1 parent 18a9b67 commit 72e0786
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/slow5_press.c
Original file line number Diff line number Diff line change
Expand Up @@ -1964,17 +1964,23 @@ unsigned char *z_inflate_buf(const char *comp_str, size_t *n) {
/*
* Zero number_of_bits LSB of number by rounding it to the nearest power of 2.
* number_of_bits must be >= 1. Return the rounded number.
* Modified from https://github.com/hasindu2008/sigtk src/qts.c.
* Taken from https://github.com/hasindu2008/sigtk src/qts.c.
*/
static int round_to_power_of_2(int number, int number_of_bits) {
//create a binary mask with the specified number of bits
int bit_mask = (1 << number_of_bits) - 1;

//extract out the value of the LSBs considered
int lsb_bits = number & bit_mask;


int round_threshold = (1 << (number_of_bits - 1));

//check if the least significant bits are closer to 0 or 2^n
if (number & (1 << (number_of_bits - 1))) {
return (number & ~bit_mask) + (1 << number_of_bits); //round up to the nearest power of 2
} else {
if (lsb_bits < round_threshold) {
return (number & ~bit_mask) + 0; //round down to the nearest power of 2
} else {
return (number & ~bit_mask) + (1 << number_of_bits); //round up to the nearest power of 2
}
}

Expand Down

0 comments on commit 72e0786

Please sign in to comment.