The math and cmath Modules
The math
module supplies mathematical functions on floating-point numbers, while the cmath
module supplies equivalent functions on complex numbers. For example, math.sqrt(-1)
raises an exception, but cmath.sqrt(-1)
returns 1j
.
Each module exposes two attributes of type float
bound to the values of fundamental mathematical constants, pi
and e
, and the following functions.
acos |
Returns the arccosine of | math and cmath |
acosh |
Returns the arc hyperbolic cosine of | cmath only |
asin |
Returns the arcsine of | math and cmath |
asinh |
Returns the arc hyperbolic sine of | cmath only |
atan |
Returns the arctangent of | math and cmath |
atanh |
Returns the arc hyperbolic tangent of | cmath only |
atan2 |
Like >>> import math >>> math.atan(-1./-1.) 0.78539816339744828 >>> math.atan2(-1., -1.) -2.3561944901923448 Also, when | math only |
ceil |
Returns | math only |
cos |
Returns the cosine of | math and cmath |
cosh |
Returns the hyperbolic cosine of | math and cmath |
e | The mathematical constant e. | math and cmath |
exp |
Returns | math and cmath |
fabs |
Returns the absolute value of | math only |
floor |
|
Get Python in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.