Inaccurate Logarithm in Python

前端 未结 9 1944
甜味超标
甜味超标 2020-12-04 01:37

I work daily with Python 2.4 at my company. I used the versatile logarithm function \'log\' from the standard math library, and when I entered log(2**31, 2) it returned 31.0

9条回答
  •  無奈伤痛
    2020-12-04 02:07

    floating-point operations are never exact. They return a result which has an acceptable relative error, for the language/hardware infrastructure.

    In general, it's quite wrong to assume that floating-point operations are precise, especially with single-precision. "Accuracy problems" section from Wikipedia Floating point article :)

提交回复
热议问题