[英]python math.log(1/2) domain error
我对python数学库的log函数有一个奇怪的问题
>> math.log(1/2)
Traceback (most recent call last):
File "<input>", line 1, in <module>
ValueError: math domain error
>> math.log(0.5)
-0.6931471805599453
为什么会这样呢? 我的python版本是2.7.9
在python 2中1/2 == 0并且log(0)是-Inf,请尝试:
math.log(1./2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.