File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
test/clojure/test_clojure Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -144,7 +144,8 @@ public BigInt add(BigInt y) {
144
144
public BigInt multiply (BigInt y ) {
145
145
if ((bipart == null ) && (y .bipart == null )) {
146
146
long ret = lpart * y .lpart ;
147
- if (y .lpart == 0 || ret / y .lpart == lpart )
147
+ if (y .lpart == 0 ||
148
+ (ret / y .lpart == lpart && lpart != Long .MIN_VALUE ))
148
149
return BigInt .valueOf (ret );
149
150
}
150
151
return BigInt .fromBigInteger (this .toBigInteger ().multiply (y .toBigInteger ()));
Original file line number Diff line number Diff line change @@ -444,6 +444,8 @@ final public Number multiply(Number x, Number y){
444
444
445
445
final public Number multiplyP (Number x , Number y ){
446
446
long lx = x .longValue (), ly = y .longValue ();
447
+ if (lx == Long .MIN_VALUE && ly < 0 )
448
+ return BIGINT_OPS .multiply (x , y );
447
449
long ret = lx * ly ;
448
450
if (ly != 0 && ret /ly != lx )
449
451
return BIGINT_OPS .multiply (x , y );
@@ -1747,13 +1749,17 @@ static public Number decP(long x){
1747
1749
1748
1750
1749
1751
static public long multiply (long x , long y ){
1752
+ if (x == Long .MIN_VALUE && y < 0 )
1753
+ return throwIntOverflow ();
1750
1754
long ret = x * y ;
1751
1755
if (y != 0 && ret /y != x )
1752
1756
return throwIntOverflow ();
1753
1757
return ret ;
1754
1758
}
1755
1759
1756
1760
static public Number multiplyP (long x , long y ){
1761
+ if (x == Long .MIN_VALUE && y < 0 )
1762
+ return multiplyP ((Number )x ,(Number )y );
1757
1763
long ret = x * y ;
1758
1764
if (y != 0 && ret /y != x )
1759
1765
return multiplyP ((Number )x ,(Number )y );
Original file line number Diff line number Diff line change 214
214
215
215
(is (> (* 3 (int (/ Integer/MAX_VALUE 2.0 ))) Integer/MAX_VALUE)) ) ; no overflow
216
216
217
+ (deftest test-multiply-longs-at-edge
218
+ (are [x] (= x 9223372036854775808N )
219
+ (*' -1 Long/MIN_VALUE)
220
+ (*' Long/MIN_VALUE -1 )
221
+ (* -1N Long/MIN_VALUE)
222
+ (* Long/MIN_VALUE -1N )
223
+ (* -1 (bigint Long/MIN_VALUE))
224
+ (* (bigint Long/MIN_VALUE) -1 ))
225
+ (is (thrown? ArithmeticException (* Long/MIN_VALUE -1 )))
226
+ (is (thrown? ArithmeticException (* -1 Long/MIN_VALUE))))
227
+
217
228
(deftest test-ratios-simplify-to-ints-where-appropriate
218
229
(testing " negative denominator (assembla #275)"
219
230
(is (integer? (/ 1 -1/2 )))
You can’t perform that action at this time.
0 commit comments