tags:

views:

387

answers:

2

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?

+5  A: 

at the bottom of the page it says:

Note: The math module consists mostly of thin wrappers around the platform C math library functions. Behavior in exceptional cases is loosely specified by the C standards, and Python inherits much of its math-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, whether math.log(0) returns -Inf or raises ValueError or OverflowError isn’t defined, and in cases where math.log(0) raises OverflowError, math.log(0L) may raise ValueError instead.

All functions return a quiet NaN if at least one of the args is NaN. Signaling NaNs raise an exception. The exception type still depends on the platform and libm implementation. It’s usually ValueError for EDOM and OverflowError for errno ERANGE.

Changed in version 2.6: In earlier versions of Python the outcome of an operation with NaN as input depended on platform and libm implementation.

SilentGhost
Does this mean that Python uses the current platform's implementation of math.h?
suppose so, here is relevant code I believe http://svn.python.org/projects/python/trunk/Include/pymath.h
SilentGhost
@paradius, how ELSE could you _possibly_ interpret "thin wrappers around the platform C math library" differently than "uses the current platform's implementation"...?
Alex Martelli
+2  A: 

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.