This module is always available. It provides access to the mathematical functions defined by the C standard.
These functions cannot be used with complex numbers; use the functions of the same name from the cmath module if you require support for complex numbers. The distinction between functions which support complex numbers and those which don't is made since most users do not want to learn quite as much mathematics as required to understand complex numbers. Receiving an exception instead of a complex result allows earlier detection of the unexpected complex number used as a parameter, so that the programmer can determine how and why it was generated in the first place.
The following functions are provided by this module. Except when explicitly noted otherwise, all return values are floats:
x) |
x) |
x) |
y, x) |
atan(y / x)
.
x) |
x) |
x) |
x) |
x) |
e**x
.
x) |
x) |
x, y) |
fmod(x, y)
, as defined by the platform C library.
Note that the Python expression x % y
may not return
the same result.
x) |
(m, e)
. m is a float and e is an
integer such that x == m * 2**e
.
If x is zero, returns (0.0, 0)
, otherwise
0.5 <= abs(m) < 1
.
x, y) |
sqrt(x*x + y*y)
.
x, i) |
x * (2**i)
.
x[, base]) |
x) |
x) |
x, y) |
x**y
.
x) |
x) |
x) |
x) |
x) |
x) |
Note that frexp() and modf() have a different call/return pattern than their C equivalents: they take a single argument and return a pair of values, rather than returning their second return value through an `output parameter' (there is no such thing in Python).
The module also defines two mathematical constants:
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.
See Also: