What do these three special floating-point values mean: positive infinity, negative infinity, NaN?

后端 未结 6 629
无人及你
无人及你 2020-12-31 12:22

How can we use them in our codes, and what will cause NaN(not a number)?

6条回答
  •  萌比男神i
    2020-12-31 12:37

    Positive Infinity is a positive number so large that it can't be represented normally. Negative Infinity is a negative number so large that it cannot be represented normally. NaN means "Not a Number" and results from a mathematical operation that doesn't yield a number- like dividing 0 by 0.

    this is not a complete answer(or not clarified enough) - consider this:

    double a = Math.pow(10,600) - Math.pow(10,600); //==NaN
    

    mathematically everybody can see it is 0. but for the machine it is an "Infinity" - "Infinity"(of same order) witch is indeed NaN...

提交回复
热议问题