repair multiply of (- (expt 2 30)) to itself

On a 64-bit platform, the test for "short" arguments to
avoid overflow was incorrect, because `(- (expt 2 30))`
counted as short.

original commit: 6d05b70e86987c0e7a07f221ba5def492300aaaf
This commit is contained in:
Matthew Flatt 2019-05-01 09:14:25 -06:00
parent 8ec5457627
commit 40ced8629e
3 changed files with 11 additions and 1 deletions

2
LOG
View File

@ -1313,3 +1313,5 @@
externs.h, system.h, expeditor.c, configure, Mf-*, Makefile.*nt,
workarea, mat.ss, io.ms, io.stex, objects.stex, release_notes.stex,
root-experr*, patch*
- fix multiply of most negative fixnum to itself on 64-bit platforms
number.c, 5_3.ms

View File

@ -637,7 +637,7 @@ static ptr big_mul(tc, x, y, xl, yl, sign) ptr tc, x, y; iptr xl, yl; IBOOL sign
return copy_normalize(&BIGIT(W(tc),0),xl+yl,sign);
}
#define SHORTMIN (most_negative_fixnum / (1 << (fixnum_bits / 2)))
#define SHORTMIN ((most_negative_fixnum / (1 << (fixnum_bits / 2))) + 1)
#define SHORTMAX (most_positive_fixnum / (1 << (fixnum_bits / 2)))
#define SHORTRANGE(x) ((x) >= SHORTMIN && (x) <= SHORTMAX)

View File

@ -1628,6 +1628,14 @@
(error? (* 'a 3 4))
(error? (* 3 5 'a 4))
(eqv? (* 1 2) 2)
(let loop ([n 0])
(or (= n 100)
(and
(eqv? (* (expt 2 n) (expt 2 n)) (expt 2 (* 2 n)))
(eqv? (* (- (expt 2 n)) (- (expt 2 n))) (expt 2 (* 2 n)))
(eqv? (* (- (expt 2 n)) (expt 2 n)) (- (expt 2 (* 2 n))))
(eqv? (* (expt 2 n) (- (expt 2 n))) (- (expt 2 (* 2 n))))
(loop (add1 n)))))
(fl~= (* 1.0 2) 2.0)
(fl~= (* 1 2.0) 2.0)
(eqv? (* 3/5 2/5) 6/25)