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 |
|
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access