Notes

Math Module

Math module in python is a module used to do all kinds of mathematical operations.

import math

Ceil Function


Return the smallest integer greater than or equal to the number.


math.ceil(3.5)

# Output is 4

Exponent Fuction


Returns e raised to the power of specified argument.


math.exp(3)

# Output is 20.085536923187668

Fabs Function


This function is used to find the absolute (mod value) of any number.


math.fabs(-2.303)

# Output is 2.303

Floor Function


This function is used to get the largest integer greater than or equal to a given number.


math.floor(4.3034)

# Output is 4

Log Function


This function is used to find logarithmic value of any number to any base.


math.log(12,11) #math.log(number,base)

# Output is 1.0362865626271018

Sine Function


This function is used to find the sine of any number.


math.sin(math.pi) # Argument always in radians

# Output is 1.2246467991473532e-16

Cos Function


This function is used to find the cosine value of any number.


math.cos(math.pi)

# Output is -1.0

Degrees Function


This function is used to convert angle which is in degrees to radians.


math.degrees(math.pi)

# Output is 180

Radians Function


This function is used to convert angles in radians to angles in radians.


math.radians(180)

# Output is 3.141592653589793

Fmod Function


This function returns the modulus (remainder) resulting from division of x from y


Diffrence between x%y and math.fmod(x,y)

It is important to note here that x%y return mod value with lesser precision which has the sign of y while math.fmod(x,y) has more precision and returns answer according to the sign of x.


math.fmod(-9,2)

# Output is -1

(-9)%2

#Output is 1


Factorial Function


This function is used to find the factorial of specified integer.


math.factorial(5)

# Output is 120

GCD Function


This function is used to find the Greatest Common Divisor of two numbers.


math.gcd(5,10)

# Output is 5