math Module in Python

math Module in Python

math module is Python contains a number of functions that are used when mathematical operations are required in the script. The functions and constants available in this module are listed below:

 

 

Methods and Functions of math Module in Python

Basic Math Functions of math Module in Python

Method Description
ceil() This method rounds the specified number up to the nearest integer.
comb() This method method returns the number of ways by which k items from n items can be chosen without giving importance to repetition and order.
copySign() This method returns a number with magnitude of the first argument and sign of the second argument.
fabs() This method returns the absolute value of the specified number.
factorial() This method returns factorial of the specified integer.
floor() This method rounds the specified number down to the nearest integer.
fmod() This method computes the remainder or the modulo operation on two arguments.
frexp() This method returns mantissa and exponent of the specified number.
fsum() This method computes and returns an accurate sum of floating point values in an iterable.
gcd() This method returns the highest common factor or the greatest common divisor of the specified arguments.
isclose() This method checks if the two specified values are close to each other. If they are, it returns True, otherwise, False.
isfinite() This method checks if the specified argument is neither an infinity nor a NaN. If it is not, True is returned, else False is returned.
isinf() This method checks if the specified argument is positive or negative infinity. If it is, True is returned, otherwise, False.
isnan() This method checks if the specified argument is a NaN which stands for not a number. If it is, True is returned, otherwise, False.
lcm() This method computes and returns the least common multiple of the specified arguments.
Idexp() Idexp(x,y) returns x*2^y.
modf() This method returns integral and fractional parts of the specified number.
nextafter() This method returns next floating-point number after the first specified number towards the second specified number.
perm() This method method returns the number of ways by which k items from n items can be chosen without repetition and with order.
prod() This method returns the product of all the elements of the input iterable.
remainder() This method computes the remainder operation on the two specified arguments as per the IEEE 754 standard.
trunc() This method returns the truncated integer part of the specified argument.
ulp() This method returns the least significant bit of the floating-point number argument.

Power and Logarithmic Functions

Function Description
exp() This function returns the exponent of e.
expm1() This function returns the exponent of e minus 1, i.e., ex-1.
log() This function is used to return the natural logarithm of a given number.
log1p() This function returns the natural logarithm of (1+number), i.e., log(1+number).
log2() This function returns the base-2 logarithm of a given number.
log10() This function returns the base-10 logarithm of a given number.
pow() This function returns base raised to the power of exponent.
sqrt() This function returns the square root of the given number.
isqrt() This function returns the integer square root of the given number.

Trigonometric Functions

Function Description
sin() This function returns the trigonometric sine of an angle in radians.
cos() This function returns the trigonometric cosine of an angle in radians.
tan() This function returns the trigonometric tangent of an angle in radians.
asin() This function returns the arc sine of a value.
acos() This function returns the arc cosine of a value.
atan() This function returns the arc tangent of a value.
atan2() This function returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).
hypot() This function returns the length of the vector from the origin to the given point.
dist() This function returns the Euclidean distance between two given points.

Hyperbolic Functions

Function Description
sinh() This function Returns the hyperbolic sine of a value.
cosh() This function returns the hyperbolic cosine of a value.
tanh() This function returns the hyperbolic tangent of a value.
asinh() This function returns the inverse hyperbolic sine of a value
acosh() This function returns the inverse hyperbolic cosine of a value
atanh() This function returns the inverse hyperbolic tangent of a value

Angular Conversion

Function Description
degrees() This function returns an angle measured in radians to an approx. equivalent angle measured in degrees.
radians() This function returns an angle measured in degrees to an approx. equivalent angle measured in radians.

Special Functions

Function Description
erf() This function returns the error function of the argument.
erfc() This function returns the complementary error function of the argument.
gamma() This function returns the gamma function of the argument.
lgamma() This function returns the natural logarithm of the absolute value of the gamma function of the argument.

Constants

Constant Description
pi This constant provides the value of 𝜋 to the available precision.
e This constant provides the value of e to the available precision.
tau This constant provides the value of Τ to the available precision.
inf This constant provides a floating-point positive infinity.
nan This constant provides a floating-point “not a number” (NaN) value.
Share this post

Leave a Reply

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