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

21.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.
asin(x) Arcsine of x.
atan(x) Arctangent 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.
exp(x) e to the x power.
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.
frexp(x) Given a float x, returns a tuple (m,e) where m is the mantissa and e the binary exponent of x, and x is equal to m * (2**e). If x is zero, returns the tuple (0.0, 0).
fmod(x,y) Returns (x-int(x/y)*y).
ldexp(x, i) Returns x * (2**i).
hypot(x,y) The square root of (x2+y2).
log(x) Natural log of x.
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.
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.