# Python math Functions

The Python math Library provides various Functions and Constants / Properties, which allows us to perform mathematical functionality. Unlike other global objects, Properties, and Functions inside the Python math library object are static. So, we can access the math properties as pi and function as abs(number).

## Object Properties

The list of Properties or Constants is available in the Python math library module.

## Python math Functions

The list of Python mathematical Functions is available in the math Library. Please follow these links to view the tutorial on the available methods.

### Python math Power and Logarithmic Functions

The following is the list of Power and logarithmic functions available in the Python math Library.

### Python Trigonometric math Functions

The following is the list of Trigonometric functions available in the Python math Library.

### Python Hyperbolic math Functions

The Python Hyperbolic trigonometric functions allow us to perform the following math functions on Hyperbolic instead of Circles.

### Python Angular math Functions

The following is the list of Angular functions available in the Python math Library.

### Python Special math Functions

The following is the list of Special functions available in the Python math Library.

## Python math Functions Examples

### constants Example

In this constants example, we use the list of available constants in the math library. They are pi, e, tau, inf, and nan.

```import math as td

print('pi Constant - Pi = ', td.pi)
print('pi Constant - Degrees of Pi = ', td.degrees(td.pi))

print('\ne Constant - e = ', td.pi)
print('e Constant - Degrees of e = ', td.degrees(td.e))

print('\ntau Constant - tau = ', td.tau)
print('tau Constant - Degrees of tau = ', td.degrees(td.tau))

print('\ninf Constant - Positive Infinity = ', td.inf)
print('inf Constant - Negative Infinity = ', -td.inf)

print('\nNaN Constant - Not a Number = ', td.nan)```
``````pi Constant - Pi =  3.141592653589793
pi Constant - Degrees of Pi =  180.0

e Constant - e =  3.141592653589793
e Constant - Degrees of e =  155.74607629780772

tau Constant - tau =  6.283185307179586
tau Constant - Degrees of tau =  360.0

inf Constant - Positive Infinity =  inf
inf Constant - Negative Infinity =  -inf

NaN Constant - Not a Number =  nan``````

### Python math Functions – fabs, ceil, floor, factorial

In this example, we will use the fabs to find the absolute value and copysign to change the sign. Next, we used the ceil and floor to find the Ceiling and Floor values. Within the last statement, we used the factorial func to find the factorial of a given value.

```import math as mh

x = 10.98
y = 30.22
z = -40.95

print('FABS  - Absolute Value of z = ', mh.fabs(z))
print('FABS  - Absolute Value of -124.897 = ', mh.fabs(-124.897))

print('\ncopysign of x, z = ', mh.copysign(x, z))
print('copysign of z, x = ', mh.copysign(z, x))

print('\nCEIL  - Ceiling of x = ', mh.ceil(x))
print('CEIL  - Ceiling of y = ', mh.ceil(y))

print('\nFLOOR  - Floor of x = ', mh.floor(x))
print('FLOOR  - Floor of y = ', mh.floor(y))

print('\nFactorial of 3 = ', mh.factorial(3))
print('Factorial of 5 = ', mh.factorial(5))```
``````FABS  - Absolute Value of z =  40.95
FABS  - Absolute Value of -124.897 =  124.897

copysign of x, z =  -10.98
copysign of z, x =  40.95

CEIL  - Ceiling of x =  11
CEIL  - Ceiling of y =  31

FLOOR  - Floor of x =  10
FLOOR  - Floor of y =  30

Factorial of 3 =  6
Factorial of 5 =  120``````

### Python math Functions – fmod, frexp, fsum, gcd

In this example, we used fmod, frexp, fsum, and gcd with different values.

```import math as gm

print('FMOD - Mod of 2 and 3 = ', gm.fmod(2, 3))
print('FMOD - Mod of 225.55 and 5.5 = ', gm.fmod(222.55, 5.5))

print('\nFREXP - Mantissa and Exponent Value of 5 = ', gm.frexp(5))
print('FREXP - Mantissa and Exponent Value of -9 = ', gm.frexp(-9))

print('\nFSUM - Sum of Tuple Items = ', gm.fsum((10, 20, 30, 40)))
print('FSUM - Sum of List Items = ', gm.fsum([5, 22, 35, 9]))

print('\nGCD of two 10 and 2 = ', gm.gcd(10, 2))
print('GCD of two 100 and 15 = ', gm.gcd(100, 15))```
``````FMOD - Mod of 2 and 3 =  2.0
FMOD - Mod of 225.55 and 5.5 =  2.5500000000000114

FREXP - Mantissa and Exponent Value of 5 =  (0.625, 3)
FREXP - Mantissa and Exponent Value of -9 =  (-0.5625, 4)

FSUM - Sum of Tuple Items =  100.0
FSUM - Sum of List Items =  71.0

GCD of two 10 and 2 =  2
GCD of two 100 and 15 =  5``````

### Python math functions – round, ldexp, modf, trunc, remainder

In this math Functions example, we used round, ldexp, mode, trunc, and remainder.

```import math as at

print('ROUND - Rounded Number 100.98763 = ', round(100.9876, 2))
print('ROUND - Rounded Number 125.932832 = ', round(125.932832, 3))

print('\nLDEXP - LDEXP (FREXP inverse) Number of 4, 5 = ', at.ldexp(4, 5))
print('LDEXP - LDEXP (FREXP inverse) Number of -9, 2 = ', at.ldexp(-9, 2))

print('\nMODF - Modf (Divided 1 to 2) Number of 100 = ', at.modf(100))
print('MODF - Modf (Divided 1 to 2) Number of 120.98 = ', at.modf(120.98))

print('\nTRUNC - Truncated Number 100.98763 = ', at.trunc(100.9876))
print('ROUND - Truncated Number 125.932832 = ', at.trunc(-125.932832))

print('\nRemainder of 29 and 5 = ', at.remainder(20, 5))
print('Remainder of 10 and 3 = ', at.remainder(10, 3))```
``````ROUND - Rounded Number 100.98763 =  100.99
ROUND - Rounded Number 125.932832 =  125.933

LDEXP - LDEXP (FREXP inverse) Number of 4, 5 =  128.0
LDEXP - LDEXP (FREXP inverse) Number of -9, 2 =  -36.0

MODF - Modf (Divided 1 to 2) Number of 100 =  (0.0, 100.0)
MODF - Modf (Divided 1 to 2) Number of 120.98 =  (0.980000000000004, 120.0)

TRUNC - Truncated Number 100.98763 =  100
ROUND - Truncated Number 125.932832 =  -125

Remainder of 29 and 5 =  0.0
Remainder of 10 and 3 =  1.0``````

### Logarithmic Functions Example

In this Python Logarithmic functions example, we use the math exp, expm1 to get exp values. Next, we used the log, log2, and log10 to get the natural logarithmic value, base 2 Logarithmic value. And base 10 logarithmic values. Then we used the pow to find x raised to the power of y and sqrt to find the square root of a number.

```import math as th

print('exp of 5 = ', th.exp(5))
print('exp of -3 = ', th.exp(-3))

print('\nexpm1 of 8 = ', th.expm1(8))
print('expm1 of -5 = ', th.expm1(-5))

print('\nLOG  - logarithmic of 5 = ', th.log(5))
print('LOG  - logarithmic of 100 Base 2 = ', th.log(100, 2))

print('\nLOG2  - logarithmic of 120 Base 2 = ', th.log2(120))

print('\nLOG10  - logarithmic of 150 Base 10 = ', th.log2(150))

print('\nPOW  - 2 Power 3  = ', th.pow(2, 3))
print('POW  - 5 Power 4  = ', th.pow(5, 4))

print('\nSQRT  - Square Root of 25 = ', th.sqrt(25))
print('SQRT  - Square Root of 19 = ', th.sqrt(19))```
``````exp of 5 =  148.4131591025766
exp of -3 =  0.049787068367863944

expm1 of 8 =  2979.9579870417283
expm1 of -5 =  -0.9932620530009145

LOG  - logarithmic of 5 =  1.6094379124341003
LOG  - logarithmic of 100 Base 2 =  6.643856189774725

LOG2  - logarithmic of 120 Base 2 =  6.906890595608519

LOG10  - logarithmic of 150 Base 10 =  7.22881869049588

POW  - 2 Power 3  =  8.0
POW  - 5 Power 4  =  625.0

SQRT  - Square Root of 25 =  5.0
SQRT  - Square Root of 19 =  4.358898943540674``````

### Trigonometric cos, sin, tan, acos, asin, atan, atan2, hypot Functions

In this Python Trigonometric math functions example, we will use the sin, cos, and tan to find the Sine, Cosine, and Tangent Values. Next, we used the acos, asin, atan, and atan2 to find the Arc cosine, Arc Sine, and Arc Tangent values. Within the last statement, we used the hypot

```import math as mt

print('COS  - Cosine of 10 = ', mt.cos(10))
print('COS  - Cosine of -15 = ', mt.cos(-15))

print('\nSIN  - Sine of 3 = ', mt.sin(3))
print('SIN  - Sine of -5 = ', mt.sin(-5))

print('\nTAN  - Tangent of 9 = ', mt.tan(9))
print('TAN  - Tangent of -3 = ', mt.tan(-3))

print('\nACOS  - Arc Cosine of 1 = ', mt.acos(1))
print('ACOS  - Arc Cosine of -0.78 = ', mt.acos(-0.78))

print('\nASIN  - Arc Sine of 1 = ', mt.asin(1))
print('ASIN  - Arc Sine of -2 = ', mt.asin(-0.42))

print('\nATAN  - Arc Tangent of 0.72 = ', mt.atan(0.72))
print('ATAN  - Arc Tangent of -2.71 = ', mt.atan(-2.71))

print('\nATAN2  - Tangent of 2, 5 = ', mt.atan2(2, 5))

print('\nHYPOT  - Hypot Value of 2, 3 = ', mt.hypot(2, 3))```
``````COS  - Cosine of 10 =  -0.8390715290764524
COS  - Cosine of -15 =  -0.7596879128588212

SIN  - Sine of 3 =  0.1411200080598672
SIN  - Sine of -5 =  0.9589242746631385

TAN  - Tangent of 9 =  -0.4523156594418099
TAN  - Tangent of -3 =  0.1425465430742778

ACOS  - Arc Cosine of 1 =  0.0
ACOS  - Arc Cosine of -0.78 =  2.4654621440291318

ASIN  - Arc Sine of 1 =  1.5707963267948966
ASIN  - Arc Sine of -2 =  -0.43344532006988595

ATAN  - Arc Tangent of 0.72 =  0.6240230529767569
ATAN  - Arc Tangent of -2.71 =  -1.2172930308235297

ATAN2  - Tangent of 2, 5 =  0.3805063771123649

HYPOT  - Hypot Value of 2, 3 =  3.6055512754639896``````

### Python math Trigonometric cosh, sinh, tanh, acosh, asinh, atanh Functions

In this Python math example, we use the Hyperbolic trigonometric functions. First, we used the cosh, sinh, and tanh to find the Hyperbolic Cosine, Sine, and Tangent Values. Next, acosh, asinh, and atanh find the Hyperbolic Arc cosine, Arc Sine, and Hyperbolic Arc Tangent values.

```import math as ma

print('COSH  - Hyperbolic Cosine of 2 = ', ma.cosh(2))
print('COSH  - Hyperbolic Cosine of -1 = ', ma.cosh(-1))

print('\nSINH  - Hyperbolic Sine of 3 = ', ma.sinh(3))
print('SINH  - Hyperbolic Sine of -5 = ', ma.sinh(-5))

print('\nTANH  - Hyperbolic Tangent of 1 = ', ma.tanh(1))
print('TANH  - Hyperbolic Tangent of -3 = ', ma.tanh(-3))

print('\nACOSH  - Hyperbolic Arc Cosine of 10 = ', ma.acosh(10))
print('ACOSH  - Hyperbolic Arc Cosine of 30.78 = ', ma.acosh(30.78))

print('\nASINH  - Hyperbolic Arc Sine of 15 = ', ma.asinh(15))
print('ASINH  - Hyperbolic Arc Sine of -25 = ', ma.asinh(-25))

print('\nATANH  - Hyperbolic Arc Tangent of 0.57 = ', ma.atanh(0.57))
print('ATANH  - Hyperbolic Arc Tangent of -0.71 = ', ma.atanh(-0.71))```
``````COSH  - Hyperbolic Cosine of 2 =  3.7621956910836314
COSH  - Hyperbolic Cosine of -1 =  1.5430806348152437

SINH  - Hyperbolic Sine of 3 =  10.017874927409903
SINH  - Hyperbolic Sine of -5 =  -74.20321057778875

TANH  - Hyperbolic Tangent of 1 =  0.7615941559557649
TANH  - Hyperbolic Tangent of -3 =  -0.9950547536867305

ACOSH  - Hyperbolic Arc Cosine of 10 =  2.993222846126381
ACOSH  - Hyperbolic Arc Cosine of 30.78 =  4.119748326708938

ASINH  - Hyperbolic Arc Sine of 15 =  3.4023066454805946
ASINH  - Hyperbolic Arc Sine of -25 =  -3.9124227656412556

ATANH  - Hyperbolic Arc Tangent of 0.57 =  0.6475228448273728
ATANH  - Hyperbolic Arc Tangent of -0.71 =  -0.8871838632580928``````

### Angular and Special Functions – degrees, radians, gamma

In this Python math Angular functions example, we used the degrees and radians to convert degrees to radians and vice versa. Next, we used gamma and lgamma to return the gamma values.

```import math as gd

print('DEGREES Function - Degrees Value of 6 = ', gd.degrees(5))
print('DEGREES Function - Degrees Value of 12 = ', gd.degrees(12))