You are on page 1of 8

MATH MODULE

Some of the most popular mathematical functions are defined in the math module. These
include trigonometric functions, representation functions, logarithmic functions, angle
conversion functions, etc. In addition, some mathematical constants are also defined in this
module. To use mathematical functions under this module, you have to import the module using import
math.

Here is the list of all the functions and attributes defined in math module with a brief explanation of what
they do.

Function Description

ceil(x) Returns the smallest integer greater than or equal to x.

copysign(x, y) Returns x with the sign of y

fabs(x) Returns the absolute value of x

factorial(x) Returns the factorial of x

floor(x) Returns the largest integer less than or equal to x

fmod(x, y) Returns the remainder when x is divided by y

frexp(x) Returns the mantissa and exponent of x as the pair (m, e)

fsum(iterable) Returns an accurate floating point sum of values in the iterable

isfinite(x) Returns True if x is neither an infinity nor a NaN (Not a Number)

isinf(x) Returns True if x is a positive or negative infinity

isnan(x) Returns True if x is a NaN

ldexp(x, i) Returns x * (2**i)

modf(x) Returns the fractional and integer parts of x

trunc(x) Returns the truncated integer value of x

exp(x) Returns e**x

expm1(x) Returns e**x - 1


log(x[, base]) Returns the logarithm of x to the base (defaults to e)

log1p(x) Returns the natural logarithm of 1+x

log2(x) Returns the base-2 logarithm of x

log10(x) Returns the base-10 logarithm of x

pow(x, y) Returns x raised to the power y

sqrt(x) Returns the square root of x

acos(x) Returns the arc cosine of x

asin(x) Returns the arc sine of x

atan(x) Returns the arc tangent of x

atan2(y, x) Returns atan(y / x)

cos(x) Returns the cosine of x

hypot(x, y) Returns the Euclidean norm, sqrt(x*x + y*y)

sin(x) Returns the sine of x

tan(x) Returns the tangent of x

degrees(x) Converts angle x from radians to degrees

radians(x) Converts angle x from degrees to radians

acosh(x) Returns the inverse hyperbolic cosine of x

asinh(x) Returns the inverse hyperbolic sine of x

atanh(x) Returns the inverse hyperbolic tangent of x

cosh(x) Returns the hyperbolic cosine of x

sinh(x) Returns the hyperbolic cosine of x

tanh(x) Returns the hyperbolic tangent of x

erf(x) Returns the error function at x

erfc(x) Returns the complementary error function at x


gamma(x) Returns the Gamma function at x

lgamma(x) Returns the natural logarithm of the absolute value of the Gamma function at x

Mathematical constant, the ratio of circumference of a circle to it's diameter


pi (3.14159...)

e mathematical constant e (2.71828...)

tau The mathematical constant τ = 6.283185…, to available precision. Tau is a

circle constant equal to 2π, the ratio of a circle’s circumference to its radius.

inf A floating-point positive infinity. (For negative infinity, use -math.inf.)


Equivalent to the output of float('inf').

nan A floating-point “not a number” (NaN) value. Equivalent to the output

of float('nan').
import math
x=5
y=-10
z=10
a=[5,10,15,20,25,30,35,40,45,50]
b=10.5
#1
print("1 : ",math.ceil(x))
#2
print("2 : ",math.copysign(x,y))
#3
print("3 : ",math.fabs(y))
#4
print("4 : ",math.factorial(x))
#5
print("5 : ",math.floor(y))
#6
print("6 : ",math.fmod(z,x))
#7
print("7 : ",math.frexp(x))
#8
print("8 : ",math.fsum(a))
#9
print("9 : ",math.isfinite(y))
#10
print("10 : ",math.isinf(x))
#11
print("11 : ",math.isnan(y))
#12
print("12 : ",math.ldexp(x,2))
#13
print("13 : ",math.modf(b))
#14
print("14 : ",math.trunc(y))
#15
print("15 : ",math.exp(x))
#16
print("16 : ",math.expm1(y))
#17
print("17 : ",math.log(x,))
#18
print("18 : ",math.log1p(x))
#19
print("19 : ",math.log2(x))
#20
print("20 : ",math.log2(x))
#21
print("21 : ",math.pow(x,z))
#22
print("22 : ",math.sqrt(x))
#23
print("23 : ",math.acos(0.5))
#24
print("24 : ",math.asin(1))
#25
print("25 : ",math.atan(-0.7))
#26
print("26 : ",math.atan2(-0.7,0.9))
#27
print("27 : ",math.cos(69))
#28
print("28 : ",math.sin(69))
#29
print("29 : ",math.tan(69))
#30
print("30 : ",math.hypot(x,z))
#31
print("31 : ",math.radians(180))
#32
print("32 : ",math.degrees(3.141592653589793))
#33
print("33 : ",math.acosh(3.141592653589793))
#34
print("34 : ",math.asinh(3.141592653589793))
#35
print("35 : ",math.atanh(0.99))
#36
print("36 : ",math.cosh(69))
#37
print("37 : ",math.sinh(69))
#38
print("38 : ",math.tanh(69))
#39
print("39 : ",math.erf(x))
#40
print("40 : ",math.erfc(x))
#41
print("41 : ",math.gamma(z))
#42
print("42 : ",math.lgamma(z))
#43
print("43 : ",math.pi)
#44
print("44 : ",math.e)
#45
print("45 : ",math.tau)
#46
print("46 : ",math.inf)
#47
print("47 : ",math.nan)
OUTPUT

1: 5

2 : -5.0

3 : 10.0

4 : 120

5 : -10

6 : 0.0

7 : (0.625, 3)

8 : 275.0

9 : True

10 : False

11 : False

12 : 20.0

13 : (0.5, 10.0)

14 : -10

15 : 148.4131591025766

16 : -0.9999546000702375

17 : 1.6094379124341003

18 : 1.791759469228055

19 : 2.321928094887362

20 : 2.321928094887362

21 : 9765625.0

22 : 2.23606797749979

23 : 1.0471975511965979

24 : 1.5707963267948966

25 : -0.6107259643892086

26 : -0.6610431688506868

27 : 0.9933903797222716

28 : -0.11478481378318722
29 : -0.11554854579453279

30 : 11.180339887498949

31 : 3.141592653589793

32 : 180.0

33 : 1.811526272460853

34 : 1.8622957433108482

35 : 2.6466524123622457

36 : 4.6268908627938936e+29

37 : 4.6268908627938936e+29

38 : 1.0

39 : 0.9999999999984626

40 : 1.537459794428035e-12

41 : 362880.0

42 : 12.801827480081467

43 : 3.141592653589793

44 : 2.718281828459045

45 : 6.283185307179586

46 : inf

47 : nan

You might also like