File tree 3 files changed +11
-2
lines changed
test/clojure/test_clojure
3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 3247
3247
[x] (cond
3248
3248
(decimal? x) x
3249
3249
(float? x) (. BigDecimal valueOf (double x))
3250
- (ratio? x) (/ (BigDecimal. (.numerator x)) (.denominator x))
3250
+ (ratio? x) (/ (BigDecimal. (.numerator ^clojure.lang.Ratio x)) (.denominator ^clojure.lang.Ratio x))
3251
+ (instance? clojure.lang.BigInt x) (.toBigDecimal ^clojure.lang.BigInt x)
3251
3252
(instance? BigInteger x) (BigDecimal. ^BigInteger x)
3252
3253
(number? x) (BigDecimal/valueOf (long x))
3253
3254
:else (BigDecimal. x)))
Original file line number Diff line number Diff line change 13
13
package clojure .lang ;
14
14
15
15
import java .math .BigInteger ;
16
+ import java .math .BigDecimal ;
16
17
17
18
public final class BigInt extends Number {
18
19
@@ -66,6 +67,13 @@ public BigInteger toBigInteger(){
66
67
return bipart ;
67
68
}
68
69
70
+ public BigDecimal toBigDecimal (){
71
+ if (bipart == null )
72
+ return BigDecimal .valueOf (lpart );
73
+ else
74
+ return new BigDecimal (bipart );
75
+ }
76
+
69
77
///// java.lang.Number:
70
78
71
79
public int intValue (){
Original file line number Diff line number Diff line change 25
25
26
26
27
27
(deftest Coerced-BigDecimal
28
- (let [v (bigdec 3 )]
28
+ (doseq [v [ (bigdec 3 ) ( bigdec ( inc ( bigint Long/MAX_VALUE)))] ]
29
29
(are [x] (true ? x)
30
30
(instance? BigDecimal v)
31
31
(number? v)
You can’t perform that action at this time.
0 commit comments