diff options
author | Rich Hickey <richhickey@gmail.com> | 2010-06-16 11:58:23 -0400 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2010-06-16 11:58:23 -0400 |
commit | d97599c35c4cf252d4ecf2a33d9af5c24ac82fa6 (patch) | |
tree | 38c8136093b444fa16bb1008091e76085270a241 | |
parent | db653b5e18501d427bf1893bca1481e4543a35bf (diff) |
bigdecs trump ratios when combined
-rw-r--r-- | src/jvm/clojure/lang/Numbers.java | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/jvm/clojure/lang/Numbers.java b/src/jvm/clojure/lang/Numbers.java index 6f4f16bf..a403395b 100644 --- a/src/jvm/clojure/lang/Numbers.java +++ b/src/jvm/clojure/lang/Numbers.java @@ -217,11 +217,20 @@ static BigDecimal toBigDecimal(Object x){ return (BigDecimal) x; else if(x instanceof BigInteger) return new BigDecimal((BigInteger) x); + else if(x instanceof Double) + return new BigDecimal(((Number) x).doubleValue()); + else if(x instanceof Float) + return new BigDecimal(((Number) x).doubleValue()); + else if(x instanceof Ratio) + { + Ratio r = (Ratio)x; + return (BigDecimal)divide(new BigDecimal(r.numerator), r.denominator); + } else return BigDecimal.valueOf(((Number) x).longValue()); } -static Ratio toRatio(Object x){ +static public Ratio toRatio(Object x){ if(x instanceof Ratio) return (Ratio) x; else if(x instanceof BigDecimal) @@ -580,7 +589,7 @@ final static class RatioOps implements Ops{ } final public Ops opsWith(BigDecimalOps x){ - return this; + return BIGDECIMAL_OPS; } public boolean isZero(Number x){ @@ -765,7 +774,7 @@ final static class BigDecimalOps implements Ops{ } final public Ops opsWith(RatioOps x){ - return RATIO_OPS; + return this; } final public Ops opsWith(BigIntegerOps x){ |