Python math module

Python math module

Python’s standard library provides the math module. This module contains many predefined functions for performing various mathematical operations. These functions do not work with complex numbers. There is also a cmath module that contains mathematical functions for complex numbers.

Functions in the math module

Below is a list of functions available in the math module:

Order number Method and description
1 acos(x) Returns the arc cosine of x (expressed in radians).
2 acosh (x) Returns the inverse hyperbolic cosine of x.
3 asin Returns the inverse sine of x (expressed in radians).
4 asinh (x) Returns the inverse hyperbolic sine of x.
5 atan Returns the inverse tangent of x (expressed in radians).
6 atan2 Returns the value of atan(y/x) (expressed in radians).
7 atanh(x) Returns the inverse hyperbolic tangent of x.
8 cbrt(x) Returns the cube root of x.
9 cell(x) Returns the smallest integer greater than or equal to x.
10 comb(x,y) Returns the number of ways to select x elements from y elements, allowing duplicates and regardless of order.
11 copysign(x,y) Returns a floating-point number with the absolute value of x but the sign of y.
12 cos(x) Returns the cosine of x in radians.
13 cosh(x) Returns the hyperbolic cosine of x.
14 degrees Converts x from radians to degrees.
15 dist(x,y) Returns the Euclidean distance between two points x and y.
16 e The mathematical constant e = 2.718281…, correct to the available precision.
17 erf(x) Returns the error function of x.
18 erfc (x) Returns the complementary error function of x.
19 exp (x) Returns e raised to the power of x, where e = 2.718281…
20 exp2 (x) Returns 2 raised to the power of x.
21 expm1 (x) Returns e raised to the power of x minus 1.
22 fabs(x) Returns the absolute value of x (floating point number)
23 factorial(x) Returns the factorial of x (integer)
24 floor(x) Returns the integer part of x, i.e., the largest integer not greater than x
25 fmod(x,y) Returns the remainder when x is divided by y, returning a floating point number
26 frexp(x) Returns the mantissa and exponent of the given number x.

27 fsum (iterable) Finds the sum of all numbers in an iterable, returning a floating-point number.

28 gamma (x) Returns the gamma function of x.
29 gcd (x,y,z) Returns the greatest common divisor of the given integer arguments.
30 hypot Returns the Euclidean norm, i.e., sqrt(xx + yy).
31 inf The positive infinity of a floating-point number. Equivalent to the output of float(‘inf’).
32 isclose (x,y) Returns True if the values x and y are close to each other, otherwise returns False.
33 isfinite (x) Returns True if the value is neither infinite nor NaN, otherwise returns False.
34 isinf (x) Returns True if x is positive infinity or negative infinity, otherwise returns False.
35 isnan(x) Returns True if x is NaN (Not a Number); otherwise, returns False.
36 isqrt(x) Returns the integer square root of the nonnegative integer x.
37 lcm(x1, x2, ..) Returns the least common multiple of the specified integer arguments.
38 ldexp(x,y) Returns x * (2**y). This is the inverse of frexp().
39 lgamma (x) Returns the natural logarithm of the absolute value of the gamma function at x.
40 log (x) Returns the natural logarithm (base e) of x.
41 log10 (x) Returns the base 10 logarithm of x.
42 log1p (x) Returns the natural logarithm (base e) of 1+x.
43 log2(x) Returns the base-2 logarithm of x.
44 modf(x) Returns a tuple of the fractional and integer parts of x. Both parts have the same sign as x. The integer part is returned as a floating-point number.
45 nan A floating-point “Not a Number” (NaN) value.
46 nextafter(x,y) Returns the next floating-point value after x in the direction of y.
47 perm (x,y) Returns the number of ways to arrange x items from y items in a non-repeated, ordered order.
48 pi The mathematical constant π = 3.141592…, with available precision.
49 pow (x,y) Returns x raised to the power of y.
50 prod (iterable) Returns the product of all elements in the input iterable.
51 radians Converts the angle x from degrees to radians.
52 remainder (x,y) Returns the remainder when x is divided by y.
53 sin (x) Returns the sine of x in radians.
54 sinh (x) Returns the inverse hyperbolic sine of x.
55 sqrt (x) Returns the square root of x.
56 tan (x) Returns the tangent of x.
57 tanh (x) Returns the hyperbolic tangent of x.
58 tau The mathematical constant τ = 6.283185…, to the available precision.
59 trunc (x) Returns the integer portion of x after removing the decimal portion.
60 ulp Returns the value of the least significant bit of the floating-point number x.

The following functions can be categorized as −

  • Theoretical and Representation Functions

  • Power and Logarithmic Functions

  • Trigonometric Functions

  • Angle Conversion Functions

  • Hyperbolic Functions

  • Special Functions

  • Mathematical Constants

Leave a Reply

Your email address will not be published. Required fields are marked *