def log1p(x):
"""log(1 + x) accurate for small x (missing from python 2.5.2)"""
if sys.version_info > (2, 6):
return math.log1p(x)
y = 1 + x
z = y - 1
# Here's the explanation for this magic: y = 1 + z, exactly, and z
# approx x, thus log(y)/z (which is nearly constant near z = 0) returns
# a good approximation to the true log(1 + x)/x. The multiplication x *
# (log(y)/z) introduces little additional error.
return x if z == 0 else x * math.log(y) / z
geomath.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录