Movatterモバイル変換


[0]ホーム

URL:


Python Tutorial

Python cmath.isinf() Function



The Pythoncmath.isinf() function checks whether a given value is positive or negative infinite.

This function returnsTrue if the specified number is infinite, otherwise it returns False.

For instance, if we have a floating point number "x = float('inf')", which represents positive infinity, i.e "True".

Syntax

Following is the basic syntax of the Pythoncmath.isinf() function −

cmath.isinf(x)

Parameters

This function accepts a numeric value as a parameter. Represents the floating point number to be infinity.

Return Value

This method returns a boolean value, i.e., True or False.

Example 1

In the below example, we are rectifying if positive infinity is infinite usingcmath.isinf() function −

import cmathx = cmath.isinf(float('inf'))print(x)

Output

The output obtained is as follows −

True

Example 2

Here, we are checking if negative infinity is infinite using thecmath.isinf() function −

import cmathres = cmath.isinf(float('-inf'))print(res)

Output

Following is the output of the above code −

True

Example 3

Now, we are checking if "100" is infinite usingcmath.isinf function −

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

Output

We will 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 thecmath.isinf() function −

import cmathresult = cmath.isinf(float('NaN'))print(result)

Output

The result is obtained as follows −

False
python_modules.htm
Print Page
Advertisements

[8]ページ先頭

©2009-2025 Movatter.jp