Message117457
> No, it's not really a bug: math.log(x, 2) isn't an atomic operation:
It is not a bug, but values of math.log(4) differs between 3.1 and 3.2
i.e., math.log(4.0) in 3.2 returns value that is consistent with
math.log(4) in 3.1 but math.log(4) in 3.2 doesn't.
> I'm not sure what you're using math.log(x, 2) for, but you may be
interested in the int.bit_length method.
The docs for int.bit_length say:
> if x is nonzero, then x.bit_length() is the unique positive integer
k such that 2**(k-1) <= abs(x) < 2**k. Equivalently, when abs(x) is
small enough to have a correctly rounded logarithm, then k = 1 +
int(log(abs(x), 2)).
It is expected that int(log(n,2)) produces correct result for small n.
> Having said that, it would be possible to improve the algorithm
that's used to compute log of an integer (see the loghelper function
in Modules/mathmodule.c): currently, for positive k, log(2**k) ends
up being computed as log(0.5) + (k+1)*log(2), which doesn't help; it
would be slightly better if it were computed directly as k*log(2)
instead. But you still can't (and shouldn't) rely on log(x, 2)
giving exact results for powers of 2.
I've changed loghelper() to return improved result for power of 2 |
|
Date |
User |
Action |
Args |
2010-09-27 18:14:24 | akira | set | recipients:
+ akira, mark.dickinson |
2010-09-27 18:14:24 | akira | set | messageid: <1285611264.03.0.638506478445.issue9959@psf.upfronthosting.co.za> |
2010-09-27 18:14:22 | akira | link | issue9959 messages |
2010-09-27 18:14:22 | akira | create | |
|