You are on page 1of 5

Math Module:

------------
Math module is providing predefined variables and functions inorder to perform
mathematgical and Scientific calculations in Python applications.
EX: Calculating Trignometric Operations.
Calculating Squere root for numbers.
Calculating Factorial functions for numbers
-----
-----
Variables:
-----------
1. math.pi
--> It will represent mathetical constrant 'π' and its value is 3.141592653589793

2. math.e
--> It will represent mathematical constant 'e' and its value is 2.718281828459045

3. math.tau
--> It will represent mathematcal constant 'τ' and its value is 6.283185307179586,
it is equals to 2π

EX:
---
import math
print(math.pi)
print(math.e)
print(math.tau)

OP:
---
3.141592653589793
2.718281828459045
6.283185307179586

Functions:
------------
1. math.ceil(x)
--> It will return a smallest integer which is greater than or equals to x.
EX:
---
import math
x = 7.3
print(math.ceil(x))
OP:
---
8

2. math.floor(x)
--> It wil return largest integer which is less than or equals to X.
EX:
---
import math
x = 7.3
print(math.floor(x))
OP:
---
7

3. math.factorial(x)
--> It will return factorial value of x.
EX:
---
import math
x = 4
print(math.factorial(x))
OP:
---
24

factorial(4) = 1*2*3*4 = 24

4. math.fabs(x)
--> it will return absolute value of x.
EX:
---
import math
x = -4
y = 5
print(math.fabs(x))
print(math.fabs(y))
OP:
---
4
5
Note: Absolute value is the distance from 0 upto the specified value in numbers
scale irrespective of the direction.

5. math.fmod(x,y)
--> It will perform modulo operation like x%y
EX:
---
import math
x = 10
y = 3
print(math.fmod(x,y))
OP:
---
1.0

6. math.fsum(list)
--> It will add all the elements of the provided list and return the result value.
EX:
---
import math
list = [1,2,3,4,5,6]
print(math.fsum(list))
Op:
--
21.0

7. math.gcd(a,b)
--> It will return the greatest common divisor of the integers a and b.
EX:
---
import math
x = 8
y = 10
print(math.gcd(x,y))
OP:
---
2

8.math.sqrt(x)
--> It will retun sque root of x.
EX:
---
import math
x = 4
print(math.sqrt(x))
OP:
---
2.0
1/2
Note: sqrt(4) = 4

9. math.remainder(x,y)
--> It will return remainder of x/y.
Ex:
----
import math
x = 10
y = 3
print(math.remainder(x,y))
OP:
---
1.0

10.math.trunc(x)
--> It will return truncated value , that is, integral value of the provided float
value.
EX:
---
import math
x = 5.9
print(math.trunc(x))
OP:
---
5

11. math.exp(x) x
--> It will return exponential of x, that is, e
EX:
---
import math
x = 3
print(math.exp(x))
OP:
---
20.085536923187668

12.math.log(x,base)
--> It will return log value of x with the provided base.
EX:
---
import math
x = 10
print(math.log(x,2))
print(math.log(x,3))
print(math.log(x,10))
OP:
---
3.3219280948873626
2.095903274289385
1.0

Note:We can use the functins like log1p(x), log2(x), log10(x) to accurate values.
EX:
---
import math
x = 10
print(math.log(x,2))
print(math.log(x,3))
print(math.log(x,10))
print()
print(math.log1p(x))
print(math.log2(x))
print(math.log10(x))
OP:
---
3.3219280948873626
2.095903274289385
1.0

2.3978952727983707
3.321928094887362
1.0

13.math.pow(x,y) y
-->It will calculate power operation between x and y, that is, x
EX:
---
import math
x = 2
y = 4
print(math.pow(x,y))
OP:
---
16.0

14.math.degrees(x)
-->It will return the value in the form of degree.
1 degree = pi/180 radians

15.math.radians(x)
--> it will return in the form of radians.
EX:
---
import math
print(math.radians(30))
print(math.degrees(0.5235987755982988))
OP:
---
0.5235987755982988
29.999999999999996

16. sin(x), cos(x), tan(x)


--> These will perfor Trignoimetric functions.
EX:
---
import math
print(math.sin(30))
print(math.cos(30))
print(math.tan(30))

OP:
---
-0.9880316240928618
0.15425144988758405
-6.405331196646276

You might also like