summaryrefslogtreecommitdiff
path: root/src/clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/clj')
-rw-r--r--src/clj/clojure/core.clj14
-rw-r--r--src/clj/clojure/core_print.clj7
-rw-r--r--src/clj/clojure/pprint/cl_format.clj2
3 files changed, 21 insertions, 2 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index b35722b6..55d4d588 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -3008,6 +3008,7 @@
[n]
(or (instance? Integer n)
(instance? Long n)
+ (instance? clojure.lang.BigInt n)
(instance? BigInteger n)
(instance? Short n)
(instance? Byte n)))
@@ -3065,6 +3066,19 @@
(or (integer? n) (ratio? n) (decimal? n)))
(defn bigint
+ "Coerce to BigInt"
+ {:tag clojure.lang.BigInt
+ :static true
+ :added "1.3"}
+ [x] (cond
+ (instance? clojure.lang.BigInt x) x
+ (instance? BigInteger x) (clojure.lang.BigInt/fromBigInteger x)
+ (decimal? x) (bigint (.toBigInteger ^BigDecimal x))
+ (ratio? x) (bigint (.bigIntegerValue ^clojure.lang.Ratio x))
+ (number? x) (clojure.lang.BigInt/valueOf (long x))
+ :else (bigint (BigInteger. x))))
+
+(defn biginteger
"Coerce to BigInteger"
{:tag BigInteger
:added "1.0"
diff --git a/src/clj/clojure/core_print.clj b/src/clj/clojure/core_print.clj
index 21af0ac9..a8a198fd 100644
--- a/src/clj/clojure/core_print.clj
+++ b/src/clj/clojure/core_print.clj
@@ -242,6 +242,7 @@
(defmethod print-dup java.lang.Double [o w] (print-method o w))
(defmethod print-dup clojure.lang.Ratio [o w] (print-method o w))
(defmethod print-dup java.math.BigDecimal [o w] (print-method o w))
+(defmethod print-dup clojure.lang.BigInt [o w] (print-method o w))
(defmethod print-dup java.math.BigInteger [o w] (print-method o w))
(defmethod print-dup clojure.lang.PersistentHashMap [o w] (print-method o w))
(defmethod print-dup clojure.lang.PersistentHashSet [o w] (print-method o w))
@@ -279,10 +280,14 @@
(.write w (str b))
(.write w "M"))
-(defmethod print-method java.math.BigInteger [b, ^Writer w]
+(defmethod print-method clojure.lang.BigInt [b, ^Writer w]
(.write w (str b))
(.write w "N"))
+(defmethod print-method java.math.BigInteger [b, ^Writer w]
+ (.write w (str b))
+ (.write w "BIGINT"))
+
(defmethod print-method java.util.regex.Pattern [p ^Writer w]
(.write w "#\"")
(loop [[^Character c & r :as s] (seq (.pattern ^java.util.regex.Pattern p))
diff --git a/src/clj/clojure/pprint/cl_format.clj b/src/clj/clojure/pprint/cl_format.clj
index 22bb11b2..5c934f31 100644
--- a/src/clj/clojure/pprint/cl_format.clj
+++ b/src/clj/clojure/pprint/cl_format.clj
@@ -247,7 +247,7 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm
for improved performance"
[base val]
(let [format-str (get java-base-formats base)]
- (if (and format-str (integer? val))
+ (if (and format-str (integer? val) (not (instance? clojure.lang.BigInt val)))
(clojure.core/format format-str val)
(base-str base val))))