How do I type a floating point infinity literal in python

fmark picture fmark · May 27, 2010 · Viewed 53.2k times · Source

How do I type a floating point infinity literal in python?

I have heard

 inf = float('inf')

is non portable. Thus, I have had the following recommended:

 inf = 1e400

Is either of these standard, or portable? What is best practice?

Answer

mmmmmm picture mmmmmm · May 27, 2010

In python 2.6 it is portable if the CPU supports it

The float() function will now turn the string nan into an IEEE 754 Not A Number value, and +inf and -inf into positive or negative infinity. This works on any platform with IEEE 754 semantics.