Skip to content

Commit c450806

Browse files
jafingerhutstuarthalloway
authored andcommitted
CLJ-1225: Correct (quot (bigint Long/MIN_VALUE) -1N) answer
Signed-off-by: Stuart Halloway <[email protected]>
1 parent 2ea3c53 commit c450806

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/jvm/clojure/lang/BigInt.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public BigInt multiply(BigInt y) {
160160

161161
public BigInt quotient(BigInt y) {
162162
if ((bipart == null) && (y.bipart == null)) {
163+
if (lpart == Long.MIN_VALUE && y.lpart == -1)
164+
return BigInt.fromBigInteger(this.toBigInteger().negate());
163165
return BigInt.valueOf(lpart / y.lpart);
164166
}
165167
return BigInt.fromBigInteger(this.toBigInteger().divide(y.toBigInteger()));

test/clojure/test_clojure/numbers.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@
300300
(is (thrown? ArithmeticException (/ 2 0)))
301301
(is (thrown? IllegalArgumentException (/))) )
302302

303+
(deftest test-divide-bigint-at-edge
304+
(are [x] (= x (-' Long/MIN_VALUE))
305+
(/ Long/MIN_VALUE -1N)
306+
(/ (bigint Long/MIN_VALUE) -1)
307+
(/ (bigint Long/MIN_VALUE) -1N)
308+
(quot Long/MIN_VALUE -1N)
309+
(quot (bigint Long/MIN_VALUE) -1)
310+
(quot (bigint Long/MIN_VALUE) -1N)))
303311

304312
;; mod
305313
;; http://en.wikipedia.org/wiki/Modulo_operation

0 commit comments

Comments
 (0)