Why check for !isNaN() after isFinite()?

后端 未结 5 923
你的背包
你的背包 2021-02-01 17:04

I came across the goog.math.isFiniteNumber function in the Google Closure Library. What it does is checking whether a given number is both finite and not NaN<

5条回答
  •  伪装坚强ぢ
    2021-02-01 17:44

    Probably for the same reason that I have implemented (isfinite(num) && isfinite(-num)) - I was getting errors from mysql complaining about putting "-nan" into the database even though I had a check for isfinite(field)...

    A useful article on this subject is http://jacksondunstan.com/articles/983 which provides an optimization ((d*0.0)==0.0)

提交回复
热议问题