内置的
Python数学库基本上是使用C的数学库吗?还是Python有一个独立于C的数学库?此外,Python数学库平台是独立的吗? 最佳答案 在
the page it says的底部:
Note: The
math
module consists mostly of thin wrappers around the platform Cmath
library functions. Behavior in exceptional cases is loosely specified by the C standards, and Python inherits much of itsmath
-function error-reporting behavior from the platform C implementation. As a result, the specific exceptions raised in error cases (and even whether some arguments are considered to be exceptional at all) are not defined in any useful cross-platform or cross-release way. For example, whethermath.log(0)
returns-Inf
or raisesValueError
orOverflowError
isn’t defined, and in cases wheremath.log(0)
raisesOverflowError
,math.log(0L)
may raiseValueError
instead.All functions return a quiet NaN if at least one of the args is
NaN
. SignalingNaN
s raise an exception. The exception type still depends on the platform and libm implementation. It’s usuallyValueError
forEDOM
andOverflowError
forerrno ERANGE
.Changed in version 2.6: In earlier versions of Python the outcome of an operation with
NaN
as input depended on platform andlibm
implementation.