Python Infinity - Any caveats?

前端 未结 5 763
说谎
说谎 2020-12-04 07:35

So Python has positive and negative infinity:

float(\"inf\"), float(\"-inf\")

This just seems like the type of feature that has to have som

5条回答
  •  無奈伤痛
    2020-12-04 07:54

    So does C99.

    The IEEE 754 floating point representation used by all modern processors has several special bit patterns reserved for positive infinity (sign=0, exp=~0, frac=0), negative infinity (sign=1, exp=~0, frac=0), and many NaN (Not a Number: exp=~0, frac≠0).

    All you need to worry about: some arithmetic may cause floating point exceptions/traps, but those aren't limited to only these "interesting" constants.

提交回复
热议问题