Next / Previous / Contents / TCC Help System / NM Tech homepage

28.1. math: Common mathematical operations

This module provides the usual basic transcendental mathematical functions. All trig functions use angles in radians. (For a similar set of functions using the complex number system, see the Python library documentation for the cmath module.)

The math module has two constant attributes:

piThe constant 3.14159...
eThe base of natural logarithms, 2.71828...

Functions in this module include:

acos(x) Angle (in radians) whose cosine is x, that is, arccosine of x.
acosh(x) Inverse hyperbolic cosine of x
asin(x) Arcsine of x.
asinh(x) Inverse hyperbolic sine of x
atan(x) Arctangent of x.
atanh(x) Inverse hyperbolic tangent of x
atan2(y,x) Angle whose slope is y/x, even if x is zero.
ceil(x) True ceiling function, defined as the smallest integer that is greater than or equal to x. For example, ceil(3.9) yields 4.0, while ceil(-3.9) yields -3.0.
cos(x) Cosine of x, where x is expressed in radians.
cosh(x) Hyperbolic cosine of x.
degrees(x For x in radians, returns that angle in degrees.
erf(x) Error function.
erfc(x) Error function complement.
exp(x) e to the x power.
fabs(x Returns the absolute value of x as a float value.
factorial(n) Returns the factorial of n, which must be a nonnegative integer.
floor(x) True floor function, defined as the largest integer that is less than or equal to x. For example, floor(3.9) is 3.0, and floor(-3.9) is -4.0.
fmod(x,y) Returns (x-int(x/y)*y).
frexp(x) For a float value x, returns a tuple (m, e) where m is the mantissa and e is the exponent. For x=0.0, it returns (0.0, 0); otherwise, abs(m) is a float in the half-open interval [0.5, 1) and e is an integer, such that x == m*2**e.
gamma(x) Gamma function.
hypot(x,y) The square root of (x2+y2).
ldexp(x, i) Returns x * (2**i). This is the inverse of frexp().
lgamma(x) Natural log of abs(gamma(x)).
log(x[, b) With one argument, returns the natural log of x. With the second argument, returns the log of x to the base b.
log10(x) Common log (base 10) of x.
modf(x) Returns a tuple (f, i) where f is the fractional part of x, i is the integral part (as a float), and both have the same sign as x.
radians(x) For x in degrees, returns that angle in radians.
sin(x) Sine of x.
sinh(x) Hyperbolic sine of x.
sqrt(x) Square root of x.
tan(x) Tangent of x.
tanh(x) Hyperbolic tangent of x.