Python math.isinf() Method



The Python math.isinf() method is used to determine whether a given number is positive or negative infinity. It returns "True" if the number is positive or negative infinity, and "False" otherwise.

For example, if you have a floating-point number "x = float('inf')", which represents positive infinity, the math.isinf(x) method will return "True", indicating that ∞ is infinite. Similarly, if you have a floating-point number "y = float('-inf')", which represents negative infinity, the math.isinf(y) method will also return "True", indicating that -∞ is infinite.

Syntax

Following is the basic syntax of the Python math.isinf() method −

math.isinf(x)

Parameters

This method accepts a numeric value as a parameter representing the floating-point number to be checked for infinity.

Return Value

The method returns a boolean value (True or False) indicating whether the given value "x" is positive or negative infinity.

Example 1

In the following example, we check if positive infinity is infinite using the math.isinf() method −

import math
result = math.isinf(float('inf'))
print("The result is:",result)       

Output

The output obtained is as follows −

The result is: True

Example 2

Here, we check if negative infinity is infinite using the math.isinf() method −

import math
result = math.isinf(float('-inf'))
print("The result is:",result)  

Output

Following is the output of the above code −

The result is: True

Example 3

Now, we are checking if the number "100" is infinite using the math.isinf() method −

import math
result = math.isinf(float(100))
print("The result is:",result)  

Output

We get the output as shown below −

The result is: False

Example 4

In this example, we are checking if NaN (Not a Number) is infinite using the math.isinf() method −

import math
result = math.isinf(float('nan'))
print("The result is:",result)  

Output

The result produced is as shown below −

The result is: False
python_maths.htm
Advertisements
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy