Fix bugs when negating SCM_MOST_POSITIVE_FIXNUM+1
authorMark H Weaver <mhw@netris.org>
Wed, 26 Jan 2011 10:21:03 +0000 (05:21 -0500)
committerAndy Wingo <wingo@pobox.com>
Fri, 28 Jan 2011 12:52:46 +0000 (13:52 +0100)
commitb5c40589ecb249b8a0989c9409c37743c1f26557
treef51ebc39184f0945a32ca99b28d05341383ea043
parent425d55f969c241d9ef5c1a5406dedb61692e1769
Fix bugs when negating SCM_MOST_POSITIVE_FIXNUM+1

* libguile/numbers.c (scm_difference, scm_product):
  Fix bugs when negating SCM_MOST_POSITIVE_FIXNUM+1,
  aka -SCM_MOST_NEGATIVE_FIXNUM.  Previously, these cases
  failed to normalize the result to a fixnum, causing
  `=', `eqv?' and `equal?' to fail, e.g.:
  (= most-negative-fixnum (- 0 (- most-negative-fixnum)))
  (= most-negative-fixnum (* -1 (- most-negative-fixnum)))
  (= most-negative-fixnum (* (- most-negative-fixnum) -1))

* test-suite/test/numbers.test: Add test cases to detect
  bugs when negating SCM_MOST_POSITIVE_FIXNUM+1 and
  SCM_MOST_NEGATIVE_FIXNUM by various methods.
libguile/numbers.c
test-suite/tests/numbers.test