Skip to content

Commit

Permalink
Handle edge case in arbitrary-precision substraction. refs #690
Browse files Browse the repository at this point in the history
Signed-off-by: Stuart Halloway <stu@Orolo.local>
  • Loading branch information
trptcolin authored and Stuart Halloway committed Jan 6, 2011
1 parent 16eef0b commit 9506ca6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/jvm/clojure/lang/Numbers.java
Expand Up @@ -167,7 +167,9 @@ static public Number minus(Object x, Object y){

static public Number minusP(Object x, Object y){
Ops yops = ops(y);
return ops(x).combine(yops).addP((Number)x, yops.negateP((Number)y));
Number negativeY = yops.negateP((Number) y);
Ops negativeYOps = ops(negativeY);
return ops(x).combine(negativeYOps).addP((Number)x, negativeY);
}

static public Number multiply(Object x, Object y){
Expand Down
6 changes: 6 additions & 0 deletions test/clojure/test_clojure/numbers.clj
Expand Up @@ -481,3 +481,9 @@ Math/pow overflows to Infinity."
(is (= (bigint (/ 100000000000000000000 3)) 33333333333333333333))
(is (= (long 10000000000000000000/3) 3333333333333333333)))

(deftest test-arbitrary-precision-subtract
(are [x y] (= x y)
9223372036854775808N (-' 0 -9223372036854775808)
clojure.lang.BigInt (class (-' 0 -9223372036854775808))
java.lang.Long (class (-' 0 -9223372036854775807))))

0 comments on commit 9506ca6

Please sign in to comment.