Mark Dickinson added the comment:
Yes, confirmed that this is not a bug, but just one of the many consequences of
approximating real numbers by floating-point numbers.
You may be interested in math.log2 and/or int.bit_length. math.log2(x) *may*
give you more accurate results than
Joshua Insel added the comment:
The same problem occurs with the log function from the C standard library,
which Python uses to implement its same-named function.
--
stage: -> resolved
status: open -> closed
___
Python tracker
New submission from Joshua Insel :
math.log(536870912, 2) should return 29.0, because 2^29 = 536870912. However,
it instead returns 29.004.
--
messages: 408986
nosy: joshinsel
priority: normal
severity: normal
status: open
title: math.log() returns improper output
type: