Mathematical Functions in Python - Special Functions and Constants


In this article, we will learn about special functions and constants available in the math module in the Python Standard Library.

Here we will discuss some constants like −

  • pi
  • e
  • inf
  • Nan
  • tau

And some functions like

  • Gamma
  • Isinf
  • Isnan
  • isfinite()
  • erf()

Let's discuss constants and their respective values −

pi3.141592…..
e2.718281…...
inf6.283185…...
nan<infinty>
tau<not a number>

Now let’s discuss some special functions and their implementation −

  • Gamma − return the value of gamma(n)

  • Isinf − checks whether the value of the function is infinity or not.

  • Isnan − check whether the return value is a number or not.

  • Isfinite − return True if the value is neither an infinity or a nan false otherwise

  • Erf − returns the error function of x.

Now let;’s take a look at an example −

Example

import math
num=10
print (math.gamma(num))

if (math.isnan(math.nan)):
   print ("The number is not a number")
else : print ("The number is a number")


if (math.isinf(math.inf)):
   print ("The number is positive infinity")
else : print ("The number is not positive infinity")

print(math.isfinite(math.inf))

Output

362880.0
The number is not a number
The number is positive infinity
False

Conclusion

In this article, we learned about the Mathematical Functions in Python - Special Functions and Constants.

Updated on: 03-Jul-2020

194 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements