How do I type a floating point infinity literal in python

后端 未结 3 1147
小蘑菇
小蘑菇 2020-12-08 13:05

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

I have heard

 inf = float(\'inf\')

is non portable. Thus, I have had t

3条回答
  •  [愿得一人]
    2020-12-08 13:15

    float('inf') is non portable as in not portable back to Python 2.5 when the string output varies between platforms. From 2.6 and onwards float('inf') is guaranteed to work on IEEE-754-compliance platforms (ref: http://www.python.org/dev/peps/pep-0754/).

    (And the recommendation seems to be in the range 1e30000, not just 1e400.)

提交回复
热议问题