Difference between Infinity and NaN (Not a number)

后端 未结 3 670
难免孤独
难免孤独 2020-12-20 23:58

When does java print Infinity and when does it print NaN?

Why is 1.0/0.0 infinity but ((1.0/0.0) - (1.0/0.0)) NaN and 0.0f/0.0f an NaN?

What is the differenc

相关标签:
3条回答
  • 2020-12-21 00:09

    1.00/0 goes infinity but infinity minus infinity is not a number.

    0 讨论(0)
  • 2020-12-21 00:24

    Because Java is following known math facts. 1.0 / 0.0 is infinity, but the others are indeterminate forms, which Java represents as NaN (not a number).

    0 讨论(0)
  • 2020-12-21 00:24

    Java's just following the IEEE 754 specification, which is consistent with most floating-point hardware nowadays.

    0 讨论(0)
提交回复
热议问题