In Python, the math.isfinite
function returns True
if the argument passed is a finite number. I want to know expression or equation (equation that generates infinite value) which will return False
, other than 'NAN'
. Passing a number divided by 0 will give error.
Asked
Active
Viewed 395 times
-3

PARVATHY
- 122
- 9
-
2`float('inf')` and `float('-inf')` are the positive and negative infinity values. Are you asking how to *produce* such a value from an expression? – Martijn Pieters Aug 09 '18 at 12:41
-
1Yes, I would like to know an equation or expression which produces such value. – PARVATHY Aug 09 '18 at 16:17
-
Then it's just a duplicate of [Alternative methods of initializing floats to '+inf', '-inf' and 'nan'](//stackoverflow.com/q/51641287) – Martijn Pieters Aug 09 '18 at 16:30
-
thanks for sharing the link.... – PARVATHY Aug 09 '18 at 17:03
2 Answers
2
Before asking a question like this, you should always read the documentation. Simply using help(math.isfinite)
in a REPL would tell you what values return False.
Help on built-in function isfinite in module math:
isfinite(...)
isfinite(x) -> bool
Return True if x is neither an infinity nor a NaN, and False otherwise.
Like Martijn Peters mentioned, float('inf')
and float('-inf')
will both produce infinite values. And in Python 3.5+, you also have math.inf
as a way to produce those values.

Edward Minnix
- 2,889
- 1
- 13
- 26
-
I would like know a valid equation or expression which generates infinite value and results this function to return false. – PARVATHY Aug 09 '18 at 16:26
1
If you want to create value of infinity you should use
float('inf') # positive infinity
These value below are all False
import math
math.isfinite(float('inf'))
math.isfinite(float('-inf'))
math.isfinite(float('nan'))

James Liu
- 497
- 3
- 8