[issue36055] Division using math.pow and math.log approximation fails

Mark Dickinson report at bugs.python.org
Wed Feb 20 13:23:20 EST 2019


Mark Dickinson <dickinsm at gmail.com> added the comment:

This isn't a bug: floating-point arithmetic is by its nature approximate, and two sequences of operations that would mathematically give the same result need not give the same result with floating-point.

I'd recommend a read of this portion of the tutorial, which goes into some of the issues involved: https://docs.python.org/3/tutorial/floatingpoint.html

Having said that, you'll get slightly better accuracy in general (one can't make specific guarantees, since everything's dependent on the platform's math library) if you use `math.sqrt(x)` instead of `math.pow(x, 0.5)`, and `math.log2(y)` instead of `math.log(y, 2)`.

----------
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36055>
_______________________________________


More information about the Python-bugs-list mailing list