Skip to content

Commit

Permalink
bigdecs trump ratios when combined
Browse files Browse the repository at this point in the history
  • Loading branch information
richhickey committed Jun 16, 2010
1 parent db653b5 commit d97599c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/jvm/clojure/lang/Numbers.java
Expand Up @@ -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)
Expand Down Expand Up @@ -580,7 +589,7 @@ final public Ops opsWith(BigIntegerOps x){
}

final public Ops opsWith(BigDecimalOps x){
return this;
return BIGDECIMAL_OPS;
}

public boolean isZero(Number x){
Expand Down Expand Up @@ -765,7 +774,7 @@ final public Ops opsWith(DoubleOps x){
}

final public Ops opsWith(RatioOps x){
return RATIO_OPS;
return this;
}

final public Ops opsWith(BigIntegerOps x){
Expand Down

0 comments on commit d97599c

Please sign in to comment.