This worked for me using the latest build of MicroPython ...After that, with '1 << 128', it started reporting "inf".
But, yes I can confirm issues with using 'int' ...Maybe raise a bug report at : https://github.com/micropython/micropython/issues
This works as expected ...So you may be able to use a workround similar to this -If using arbitrary values you could craft your own float to integer routine.
Code:
MPY: soft rebootMicroPython v1.26.0-preview.31.g076e07197.dirty on 2025-04-25; Raspberry Pi Pico 2 W with RP2350Type "help()" for more information.>>> import math>>> math.log2(8192)13.0>>> math.log2(1 << 13)13.0>>> math.log2(1 << 14)14.0>>> math.log2(1 << 127)127.0But, yes I can confirm issues with using 'int' ...
Code:
>>> int(math.log2(1 << 13))12>>> int(math.log2(1 << 14))14>>> int(math.log2(1 << 15))14>>> int(math.log2(1 << 127))127This works as expected ...
Code:
>>> str(math.log2(1 << 13))'13.0'>>> str(math.log2(1 << 14))'14.0'>>> str(math.log2(1 << 15))'15.0'>>> str(math.log2(1 << 127))'127.0'Code:
>>> int(str(math.log2(1 << 13))[:-2])13>>> int(str(math.log2(1 << 14))[:-2])14>>> int(str(math.log2(1 << 15))[:-2])15>>> int(str(math.log2(1 << 127))[:-2])127Statistics: Posted by hippy — Sun Apr 27, 2025 12:18 am