Permalink
Browse files

CLJS-370: Fix integer? for integral floating point expressions

  • Loading branch information...
1 parent c8bc05c commit 3c210d9430b30ffeac9600ae4851e1c347c2cced @brandonbloom brandonbloom committed with David Nolen Sep 3, 2012
Showing with 12 additions and 2 deletions.
  1. +3 −2 src/cljs/cljs/core.cljs
  2. +9 −0 test/cljs/cljs/core_test.cljs
@@ -1016,10 +1016,11 @@ reduces them without incurring seq initialization"
(or (fn? f) (satisfies? IFn f)))
(defn ^boolean integer?
- "Returns true if n is an integer. Warning: returns true on underflow condition."
+ "Returns true if n is an integer."
[n]
(and (number? n)
- (coercive-= n (.toFixed n))))
+ (coercive-= (js/parseFloat n) (js/parseInt n 10))
+ (not (js/isNaN n))))
(defn ^boolean contains?
"Returns true if key is present in the given collection, otherwise
@@ -165,6 +165,15 @@
(assert (= [[1 1] [1 2] [1 3] [2 1] [2 2] [2 3]]
(map #(%) (for [i [1 2] j [1 2 3]] (fn [] [i j])))))
+ (assert (integer? 0))
+ (assert (integer? 42))
+ (assert (integer? -42))
+ (assert (not (integer? "")))
+ (assert (not (integer? 1e308)))
+ (assert (not (integer? js/Infinity)))
+ (assert (not (integer? (- js/Infinity))))
+ (assert (not (integer? js/NaN)))
+
(assert (= 42 (int 42.5)))
(assert (integer? (int 42.5)))

0 comments on commit 3c210d9

Please sign in to comment.