boostorg / dynamic_bitset

Boost.org dynamic_bitset module
http://boost.org/libs/dynamic_bitset
Boost Software License 1.0
38 stars 59 forks source link

Update calc_num_blocks(). Avoid using modulo operator. #58

Closed einiemand closed 1 week ago

einiemand commented 3 years ago

num_bits + bits_per_block - 1 is unlikely to overflow. After the change, it could be a little faster.

akr-akari commented 2 years ago

return static_cast<size_type>(std::ceil(static_cast<double>(num_bits) / bits_per_block));

jeking3 commented 1 week ago

While unlikely to overflow, it is still possible. If the overflow situation can be tested for and faster logic used, that seems fine. Otherwise the proposed change is not safe in all situations, despite being an extreme outlier, as the original code is. Given this, I am closing this PR since it has not had an update for years.