mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-21 03:00:19 +02:00
Avoid signed integer overflow in scm_product
* libguile/numbers.c (scm_product): Avoid signed integer overflow, which modern C compilers are allowed to assume will never happen, thus allowing them to optimize out our overflow checks. * test-suite/tests/numbers.test (*): Add tests.
This commit is contained in:
parent
e6a730b22a
commit
2355f01709
2 changed files with 20 additions and 4 deletions
|
@ -3070,6 +3070,16 @@
|
|||
(pass-if (eqv? fixnum-min (* (* fixnum-min -1) -1)))
|
||||
(pass-if (equal? fixnum-min (* (* fixnum-min -1) -1))))
|
||||
|
||||
(with-test-prefix "signed fixnum overflow"
|
||||
(pass-if (eqv? (* 65536 65536) 4294967296))
|
||||
(pass-if (eqv? (* -65536 65536) -4294967296))
|
||||
(pass-if (eqv? (* 65536 -65536) -4294967296))
|
||||
(pass-if (eqv? (* -65536 -65536) 4294967296))
|
||||
(pass-if (eqv? (* 4294967296 4294967296) 18446744073709551616))
|
||||
(pass-if (eqv? (* -4294967296 4294967296) -18446744073709551616))
|
||||
(pass-if (eqv? (* 4294967296 -4294967296) -18446744073709551616))
|
||||
(pass-if (eqv? (* -4294967296 -4294967296) 18446744073709551616)))
|
||||
|
||||
(with-test-prefix "signed zeroes"
|
||||
(pass-if (eqv? +0.0 (* +0.0 +0.0)))
|
||||
(pass-if (eqv? -0.0 (* -0.0 +0.0)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue