scott-griffiths / bitstring

A Python module to help you manage your bits
https://bitstring.readthedocs.io/en/stable/index.html
MIT License
401 stars 67 forks source link

Auto scaling rounding wrong way on occasion. #334

Closed scott-griffiths closed 2 months ago

scott-griffiths commented 2 months ago

At the moment the autoscaling algorithm uses

log2 = int(math.log2(max_float_value))

The int() rounds towards zero, but we want to find the largest power of two less than this max value. Therefore we should round to -inf and use math.floor.

Need to write some failing tests (perhaps compare with gfloat) and fix it.