Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
64
rated 0 times [  65] [ 1]  / answers: 1 / hits: 17052  / 13 Years ago, sat, april 16, 2011, 12:00:00

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.



The underlying code is:



goog.math.isFiniteNumber = function(num) {
return isFinite(num) && !isNaN(num);
};


So, first it checks whether the number is finite using the native isFinite function, and then does an additional check to make sure the number isn't NaN using isNaN.



However, isFinite already returns false in case the argument is NaN. So, what advantages does the check for isNaN provide?


More From » nan

 Answers
6

If isFinite worked the way isFiniteNumber did, then there would be no reason to write isFiniteNumber. There's probably some browser out there somewhere that treats NaN as finite.


[#92687] Thursday, April 14, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zahrafrancisr

Total Points: 176
Total Questions: 105
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;