When can Java produce a NaN?

前端 未结 4 1822
太阳男子
太阳男子 2020-12-20 15:33

I know what Java Double.NaN is. I have some Java code that produces NaN.

// calculate errors
delta = m1 + m2 - M;
eta = f1 + f2          


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 16:01

    NaN is triggered by the following occurrences:

    • results that are complex values
      • √x where x is negative
      • log(x) where x is negative
      • tan(x) where x mod 180 is 90
      • asin(x) or acos(x) where x is outside [-1..1]
    • 0/0
    • ∞/∞
    • ∞/−∞
    • −∞/∞
    • −∞/−∞
    • 0×∞
    • 0×−∞
    • 1
    • ∞ + (−∞)
    • (−∞) + ∞

    Sorry for such a general answer, but I hope that helped.

提交回复
热议问题