* abs_most_negative_fixnum
@ 2004-03-27 21:52 Kevin Ryde
0 siblings, 0 replies; only message in thread
From: Kevin Ryde @ 2004-03-27 21:52 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 343 bytes --]
* numbers.c (scm_quotient, scm_remainder): In inum/big, use mpz_cmp_ui
for big == abs(most-negative-fixnum) special case.
(abs_most_negative_fixnum): Remove, no longer used.
* tests/numbers.test (quotient, remainder): Exercise inum/big at and
near special case inum == fixnum-min, big == -fixnum-min.
[-- Attachment #2: numbers.c.qr-ib.diff --]
[-- Type: text/plain, Size: 1702 bytes --]
--- numbers.c.~1.229.~ 2004-03-26 07:55:12.000000000 +1000
+++ numbers.c 2004-03-27 19:12:47.000000000 +1000
@@ -148,7 +148,6 @@
\f
-static SCM abs_most_negative_fixnum;
static mpz_t z_negative_one;
\f
@@ -703,9 +702,13 @@
else if (SCM_BIGP (y))
{
if ((SCM_INUM (x) == SCM_MOST_NEGATIVE_FIXNUM)
- && (scm_i_bigcmp (abs_most_negative_fixnum, y) == 0))
- /* Special case: x == fixnum-min && y == abs (fixnum-min) */
- return SCM_MAKINUM (-1);
+ && (mpz_cmp_ui (SCM_I_BIG_MPZ (y),
+ - SCM_MOST_NEGATIVE_FIXNUM) == 0))
+ {
+ /* Special case: x == fixnum-min && y == abs (fixnum-min) */
+ scm_remember_upto_here_1 (y);
+ return SCM_MAKINUM (-1);
+ }
else
return SCM_MAKINUM (0);
}
@@ -779,9 +782,13 @@
else if (SCM_BIGP (y))
{
if ((SCM_INUM (x) == SCM_MOST_NEGATIVE_FIXNUM)
- && (scm_i_bigcmp (abs_most_negative_fixnum, y) == 0))
- /* Special case: x == fixnum-min && y == abs (fixnum-min) */
- return SCM_MAKINUM (0);
+ && (mpz_cmp_ui (SCM_I_BIG_MPZ (y),
+ - SCM_MOST_NEGATIVE_FIXNUM) == 0))
+ {
+ /* Special case: x == fixnum-min && y == abs (fixnum-min) */
+ scm_remember_upto_here_1 (y);
+ return SCM_MAKINUM (0);
+ }
else
return x;
}
@@ -5690,9 +5697,6 @@
void
scm_init_numbers ()
{
- abs_most_negative_fixnum = scm_i_long2big (- SCM_MOST_NEGATIVE_FIXNUM);
- scm_permanent_object (abs_most_negative_fixnum);
-
mpz_init_set_si (z_negative_one, -1);
/* It may be possible to tune the performance of some algorithms by using
[-- Attachment #3: numbers.test.qr-ib.diff --]
[-- Type: text/plain, Size: 1360 bytes --]
--- numbers.test.~1.44.~ 2004-03-26 07:45:06.000000000 +1000
+++ numbers.test 2004-03-27 19:11:43.000000000 +1000
@@ -324,7 +324,17 @@
(eqv? 1 (quotient fixnum-min fixnum-min)))
(pass-if "n = fixnum-min - 1"
- (eqv? 0 (quotient fixnum-min (- fixnum-min 1)))))
+ (eqv? 0 (quotient fixnum-min (- fixnum-min 1))))
+
+ (pass-if "n = - fixnum-min - 1"
+ (eqv? -1 (quotient fixnum-min (1- (- fixnum-min)))))
+
+ ;; special case, normally inum/big is zero
+ (pass-if "n = - fixnum-min"
+ (eqv? -1 (quotient fixnum-min (- fixnum-min))))
+
+ (pass-if "n = - fixnum-min + 1"
+ (eqv? 0 (quotient fixnum-min (1+ (- fixnum-min))))))
(with-test-prefix "(fixnum-min - 1) / n"
@@ -512,7 +522,17 @@
(eqv? 0 (remainder fixnum-min fixnum-min)))
(pass-if "n = fixnum-min - 1"
- (eqv? fixnum-min (remainder fixnum-min (- fixnum-min 1)))))
+ (eqv? fixnum-min (remainder fixnum-min (- fixnum-min 1))))
+
+ (pass-if "n = - fixnum-min - 1"
+ (eqv? -1 (remainder fixnum-min (1- (- fixnum-min)))))
+
+ ;; special case, normally inum%big is the inum
+ (pass-if "n = - fixnum-min"
+ (eqv? 0 (remainder fixnum-min (- fixnum-min))))
+
+ (pass-if "n = - fixnum-min + 1"
+ (eqv? fixnum-min (remainder fixnum-min (1+ (- fixnum-min))))))
(with-test-prefix "(fixnum-min - 1) / n"
[-- Attachment #4: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-03-27 21:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-27 21:52 abs_most_negative_fixnum Kevin Ryde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).