Does the built-in Python math library basically use C's math library or does Python have a C-independent math library? Also, is the Python math library platform independent?
内置的Python数学库基本上是使用C的数学库吗?还是Python有一个独立于C的数学库?此外,Python数学库平台是独立的吗?
2 个解决方案
#1
at the bottom of 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.注意:math模块主要包含围绕平台C数学库函数的瘦包装器。特殊情况下的行为由C标准松散地指定,并且Python从平台C实现继承了其大部分数学函数错误报告行为。因此,在错误情况下引发的特定异常(甚至某些参数被认为是特殊的)都没有以任何有用的跨平台或交叉发布方式定义。例如,math.log(0)是否返回-Inf或引发ValueError或OverflowError未定义,并且在math.log(0)引发OverflowError的情况下,math.log(0L)可能会引发ValueError。
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
.如果至少有一个参数是NaN,则所有函数都返回一个安静的NaN。信令NaNs引发异常。异常类型仍取决于平台和libm实现。它通常是EDOM的ValueError和errno ERANGE的OverflowError。
Changed in version 2.6: In earlier versions of Python the outcome of an operation with
NaN
as input depended on platform andlibm
implementation.版本2.6中更改:在早期版本的Python中,使用NaN作为输入的操作的结果取决于平台和libm实现。
#2
Python uses the C library it is linked against. On Windows, there is no 'platform C library'.. and indeed there are multiple versions of MicrosoftCRunTimeLibrarys (MSCRTs) around on any version.
Python使用它链接的C库。在Windows上,没有'平台C库'..并且确实在任何版本上都有多个版本的MicrosoftCRunTimeLibrarys(MSCRT)。
#1
at the bottom of 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.注意:math模块主要包含围绕平台C数学库函数的瘦包装器。特殊情况下的行为由C标准松散地指定,并且Python从平台C实现继承了其大部分数学函数错误报告行为。因此,在错误情况下引发的特定异常(甚至某些参数被认为是特殊的)都没有以任何有用的跨平台或交叉发布方式定义。例如,math.log(0)是否返回-Inf或引发ValueError或OverflowError未定义,并且在math.log(0)引发OverflowError的情况下,math.log(0L)可能会引发ValueError。
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
.如果至少有一个参数是NaN,则所有函数都返回一个安静的NaN。信令NaNs引发异常。异常类型仍取决于平台和libm实现。它通常是EDOM的ValueError和errno ERANGE的OverflowError。
Changed in version 2.6: In earlier versions of Python the outcome of an operation with
NaN
as input depended on platform andlibm
implementation.版本2.6中更改:在早期版本的Python中,使用NaN作为输入的操作的结果取决于平台和libm实现。
#2
Python uses the C library it is linked against. On Windows, there is no 'platform C library'.. and indeed there are multiple versions of MicrosoftCRunTimeLibrarys (MSCRTs) around on any version.
Python使用它链接的C库。在Windows上,没有'平台C库'..并且确实在任何版本上都有多个版本的MicrosoftCRunTimeLibrarys(MSCRT)。