Skip to content

Commit

Permalink
CLJS-807: Emitter cannot emit BigInt or BigDecimal
Browse files Browse the repository at this point in the history
Extend compiler to emit double-approximations of BigInt and BigDecimal so
that literal forms like "1N" or "1.5M" can compile.
  • Loading branch information
favila authored and swannodette committed Dec 3, 2014
1 parent 6bf7d8e commit dbb7e43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/clj/cljs/compiler.clj
Expand Up @@ -167,6 +167,8 @@
(defmethod emit-constant Long [x] (emits "(" x ")"))
(defmethod emit-constant Integer [x] (emits x)) ; reader puts Integers in metadata
(defmethod emit-constant Double [x] (emits x))
(defmethod emit-constant BigDecimal [x] (emits (.doubleValue ^BigDecimal x)))
(defmethod emit-constant clojure.lang.BigInt [x] (emits (.doubleValue ^clojure.lang.BigInt x)))
(defmethod emit-constant String [x]
(emits (wrap-in-double-quotes (escape-string x))))
(defmethod emit-constant Boolean [x] (emits (if x "true" "false")))
Expand Down
6 changes: 6 additions & 0 deletions test/cljs/cljs/core_test.cljs
Expand Up @@ -2460,5 +2460,11 @@

(assert (= {:foo true} (meta ^:foo (fn []))))

;; CLJS-807
(assert (= -1 -1N))
(assert (= 9.007199254740996E15 9007199254740995N))
(assert (= 1.5 1.5M))
(assert (= 4.9E-324 5E-324M))

:ok
)

0 comments on commit dbb7e43

Please sign in to comment.