Permalink
Browse files

Make bigdec work on clojure.lang.BigInt args

  • Loading branch information...
jafingerhut authored and stuarthalloway committed Mar 21, 2012
1 parent 82fb40a commit fb653b70b53cdc53ec4606ba420e4886bc4f0512
Showing with 11 additions and 2 deletions.
  1. +2 −1 src/clj/clojure/core.clj
  2. +8 −0 src/jvm/clojure/lang/BigInt.java
  3. +1 −1 test/clojure/test_clojure/numbers.clj
View
@@ -3247,7 +3247,8 @@
[x] (cond
(decimal? x) x
(float? x) (. BigDecimal valueOf (double x))
- (ratio? x) (/ (BigDecimal. (.numerator x)) (.denominator x))
+ (ratio? x) (/ (BigDecimal. (.numerator ^clojure.lang.Ratio x)) (.denominator ^clojure.lang.Ratio x))
+ (instance? clojure.lang.BigInt x) (.toBigDecimal ^clojure.lang.BigInt x)
(instance? BigInteger x) (BigDecimal. ^BigInteger x)
(number? x) (BigDecimal/valueOf (long x))
:else (BigDecimal. x)))
@@ -13,6 +13,7 @@
package clojure.lang;
import java.math.BigInteger;
+import java.math.BigDecimal;
public final class BigInt extends Number{
@@ -66,6 +67,13 @@ public BigInteger toBigInteger(){
return bipart;
}
+public BigDecimal toBigDecimal(){
+ if(bipart == null)
+ return BigDecimal.valueOf(lpart);
+ else
+ return new BigDecimal(bipart);
+}
+
///// java.lang.Number:
public int intValue(){
@@ -25,7 +25,7 @@
(deftest Coerced-BigDecimal
- (let [v (bigdec 3)]
+ (doseq [v [(bigdec 3) (bigdec (inc (bigint Long/MAX_VALUE)))]]
(are [x] (true? x)
(instance? BigDecimal v)
(number? v)

0 comments on commit fb653b7

Please sign in to comment.