Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for NaN in ClojureScript

How can I check if a value is NaN? I'd prefer a solution that can be used in Clojure too without much extra stuff (so I don't want to use an external library, such as underscore). Here is what I tried

(number? js/NaN) ;=> true, well I'd expect false
(= js/NaN (js/parseInt "xx")) ;=> false
(= js/NaN js/NaN) ;=> false, even worse

; This is the best I could come up with
(defn actual-number? 
  [n] 
  (or (> 0 n) (<= 0 n)))
like image 483
Adam Schmideg Avatar asked Jun 07 '13 12:06

Adam Schmideg


1 Answers

You shouldn't compare NaN's - they're always unequal. You should be able to use javascript's built-in isNaN function like

(js/isNaN x)
like image 50
Joost Diepenmaat Avatar answered Sep 23 '22 03:09

Joost Diepenmaat