guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 33/69: Integer library takes bignums via opaque struct p


From: Andy Wingo
Subject: [Guile-commits] 33/69: Integer library takes bignums via opaque struct pointer
Date: Fri, 7 Jan 2022 08:27:10 -0500 (EST)

wingo pushed a commit to branch wip-inline-digits
in repository guile.

commit ce8521aafa4e9397d0f392c5bccb51dc3d5b60ad
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Tue Jan 4 10:33:52 2022 +0100

    Integer library takes bignums via opaque struct pointer
    
    * libguile/integers.h (scm_bignum): Declare opaque struct type and a
    function to cast SCM to this type.  Adapt all routines that take bignums
    to take a "struct scm_bignum *".
    * libguile/integers.c: Adapt.
    * libguile/numbers.c: Adapt all users.
---
 libguile/integers.c | 376 ++++++++++++++++++++++++++--------------------------
 libguile/integers.h | 202 ++++++++++++----------------
 libguile/numbers.c  | 164 +++++++++++++----------
 3 files changed, 365 insertions(+), 377 deletions(-)

diff --git a/libguile/integers.c b/libguile/integers.c
index baa95b129..db806b35f 100644
--- a/libguile/integers.c
+++ b/libguile/integers.c
@@ -67,13 +67,6 @@ struct scm_bignum
   mp_limb_t limbs[];
 };
 
-static inline struct scm_bignum *
-scm_bignum (SCM x)
-{
-  ASSERT (SCM_BIGP (x));
-  return (struct scm_bignum *) SCM_UNPACK (x);
-}
-
 static int
 bignum_size (struct scm_bignum *z)
 {
@@ -184,12 +177,18 @@ long_to_bignum (long i)
   return make_bignum_1 (1, long_magnitude (i));
 };
 
+static inline SCM
+scm_from_bignum (struct scm_bignum *x)
+{
+  return SCM_PACK (x);
+}
+
 static SCM
 long_to_scm (long i)
 {
   if (SCM_FIXABLE (i))
     return SCM_I_MAKINUM (i);
-  return SCM_PACK (long_to_bignum (i));
+  return scm_from_bignum (long_to_bignum (i));
 }
 
 static SCM
@@ -197,7 +196,7 @@ ulong_to_scm (unsigned long i)
 {
   if (SCM_POSFIXABLE (i))
     return SCM_I_MAKINUM (i);
-  return SCM_PACK (ulong_to_bignum (i));
+  return scm_from_bignum (ulong_to_bignum (i));
 }
 
 static struct scm_bignum *
@@ -245,7 +244,7 @@ normalize_bignum (struct scm_bignum *z)
     default:
       break;
     }
-  return SCM_PACK (z);
+  return scm_from_bignum (z);
 }
 
 static SCM
@@ -291,9 +290,9 @@ scm_is_integer_odd_i (scm_t_inum i)
 }
 
 int
-scm_is_integer_odd_z (SCM z)
+scm_is_integer_odd_z (struct scm_bignum *z)
 {
-  return bignum_limbs (scm_bignum (z))[0] & 1;
+  return bignum_limbs (z)[0] & 1;
 }
 
 SCM
@@ -306,12 +305,12 @@ scm_integer_abs_i (scm_t_inum i)
 }
 
 SCM
-scm_integer_abs_z (SCM z)
+scm_integer_abs_z (struct scm_bignum *z)
 {
-  if (!bignum_is_negative (scm_bignum (z)))
-    return z;
+  if (!bignum_is_negative (z))
+    return scm_from_bignum (z);
 
-  return SCM_PACK (negate_bignum (clone_bignum (scm_bignum (z))));
+  return scm_from_bignum (negate_bignum (clone_bignum (z)));
 }
 
 SCM
@@ -331,23 +330,23 @@ scm_integer_floor_quotient_ii (scm_t_inum x, scm_t_inum y)
 }
 
 SCM
-scm_integer_floor_quotient_iz (scm_t_inum x, SCM y)
+scm_integer_floor_quotient_iz (scm_t_inum x, struct scm_bignum *y)
 {
-  if (x == 0 || ((x < 0) == bignum_is_negative (scm_bignum (y))))
+  if (x == 0 || ((x < 0) == bignum_is_negative (y)))
     return SCM_INUM0;
   return SCM_I_MAKINUM (-1);
 }
  
 SCM
-scm_integer_floor_quotient_zi (SCM x, scm_t_inum y)
+scm_integer_floor_quotient_zi (struct scm_bignum *x, scm_t_inum y)
 {
   if (y == 0)
     scm_num_overflow ("floor-quotient");
   else if (y == 1)
-    return x;
+    return scm_from_bignum (x);
 
   mpz_t zx, q;
-  alias_bignum_to_mpz (scm_bignum (x), zx);
+  alias_bignum_to_mpz (x, zx);
   mpz_init (q);
   if (y > 0)
     mpz_fdiv_q_ui (q, zx, y);
@@ -361,11 +360,11 @@ scm_integer_floor_quotient_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_floor_quotient_zz (SCM x, SCM y)
+scm_integer_floor_quotient_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
   mpz_t zx, zy, q;
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_init (q);
   mpz_fdiv_q (q, zx, zy);
   scm_remember_upto_here_2 (x, y);
@@ -385,15 +384,15 @@ scm_integer_floor_remainder_ii (scm_t_inum x, scm_t_inum 
y)
 }
 
 SCM
-scm_integer_floor_remainder_iz (scm_t_inum x, SCM y)
+scm_integer_floor_remainder_iz (scm_t_inum x, struct scm_bignum *y)
 {
-  if (bignum_is_positive (scm_bignum (y)))
+  if (bignum_is_positive (y))
     {
       if (x < 0)
         {
           mpz_t r, zy;
           mpz_init (r);
-          alias_bignum_to_mpz (scm_bignum (y), zy);
+          alias_bignum_to_mpz (y, zy);
           mpz_sub_ui (r, zy, -x);
           scm_remember_upto_here_1 (y);
           return take_mpz (r);
@@ -407,7 +406,7 @@ scm_integer_floor_remainder_iz (scm_t_inum x, SCM y)
     {
       mpz_t r, zy;
       mpz_init (r);
-      alias_bignum_to_mpz (scm_bignum (y), zy);
+      alias_bignum_to_mpz (y, zy);
       mpz_add_ui (r, zy, x);
       scm_remember_upto_here_1 (y);
       return take_mpz (r);
@@ -415,7 +414,7 @@ scm_integer_floor_remainder_iz (scm_t_inum x, SCM y)
 }
 
 SCM
-scm_integer_floor_remainder_zi (SCM x, scm_t_inum y)
+scm_integer_floor_remainder_zi (struct scm_bignum *x, scm_t_inum y)
 {
   if (y == 0)
     scm_num_overflow ("floor-remainder");
@@ -423,7 +422,7 @@ scm_integer_floor_remainder_zi (SCM x, scm_t_inum y)
     {
       scm_t_inum r;
       mpz_t zx;
-      alias_bignum_to_mpz (scm_bignum (x), zx);
+      alias_bignum_to_mpz (x, zx);
       if (y > 0)
         r = mpz_fdiv_ui (zx, y);
       else
@@ -434,11 +433,11 @@ scm_integer_floor_remainder_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_floor_remainder_zz (SCM x, SCM y)
+scm_integer_floor_remainder_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
   mpz_t zx, zy, r;
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_init (r);
   mpz_fdiv_r (r, zx, zy);
   scm_remember_upto_here_2 (x, y);
@@ -466,14 +465,14 @@ scm_integer_floor_divide_ii (scm_t_inum x, scm_t_inum y, 
SCM *qp, SCM *rp)
 }
 
 void
-scm_integer_floor_divide_iz (scm_t_inum x, SCM y, SCM *qp, SCM *rp)
+scm_integer_floor_divide_iz (scm_t_inum x, struct scm_bignum *y, SCM *qp, SCM 
*rp)
 {
-  if (bignum_is_positive (scm_bignum (y)))
+  if (bignum_is_positive (y))
     {
       if (x < 0)
         {
           mpz_t zy, r;
-          alias_bignum_to_mpz (scm_bignum (y), zy);
+          alias_bignum_to_mpz (y, zy);
           mpz_init (r);
           mpz_sub_ui (r, zy, -x);
           scm_remember_upto_here_1 (y);
@@ -494,7 +493,7 @@ scm_integer_floor_divide_iz (scm_t_inum x, SCM y, SCM *qp, 
SCM *rp)
   else
     {
       mpz_t zy, r;
-      alias_bignum_to_mpz (scm_bignum (y), zy);
+      alias_bignum_to_mpz (y, zy);
       mpz_init (r);
       mpz_add_ui (r, zy, x);
       scm_remember_upto_here_1 (y);
@@ -504,13 +503,13 @@ scm_integer_floor_divide_iz (scm_t_inum x, SCM y, SCM 
*qp, SCM *rp)
 }
 
 void
-scm_integer_floor_divide_zi (SCM x, scm_t_inum y, SCM *qp, SCM *rp)
+scm_integer_floor_divide_zi (struct scm_bignum *x, scm_t_inum y, SCM *qp, SCM 
*rp)
 {
   if (y == 0)
     scm_num_overflow ("floor-divide");
 
   mpz_t zx, q, r;
-  alias_bignum_to_mpz (scm_bignum (x), zx);
+  alias_bignum_to_mpz (x, zx);
   mpz_init (q);
   mpz_init (r);
   if (y > 0)
@@ -526,13 +525,13 @@ scm_integer_floor_divide_zi (SCM x, scm_t_inum y, SCM 
*qp, SCM *rp)
 }
 
 void
-scm_integer_floor_divide_zz (SCM x, SCM y, SCM *qp, SCM *rp)
+scm_integer_floor_divide_zz (struct scm_bignum *x, struct scm_bignum *y, SCM 
*qp, SCM *rp)
 {
   mpz_t zx, zy, q, r;
   mpz_init (q);
   mpz_init (r);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_fdiv_qr (q, r, zx, zy);
   scm_remember_upto_here_2 (x, y);
   *qp = take_mpz (q);
@@ -558,14 +557,14 @@ scm_integer_ceiling_quotient_ii (scm_t_inum x, scm_t_inum 
y)
 }
 
 SCM
-scm_integer_ceiling_quotient_iz (scm_t_inum x, SCM y)
+scm_integer_ceiling_quotient_iz (scm_t_inum x, struct scm_bignum *y)
 {
-  if (bignum_is_positive (scm_bignum (y)))
+  if (bignum_is_positive (y))
     {
       if (x > 0)
         return SCM_INUM1;
       else if (x == SCM_MOST_NEGATIVE_FIXNUM &&
-               bignum_cmp_long (scm_bignum (y), -SCM_MOST_NEGATIVE_FIXNUM) == 
0)
+               bignum_cmp_long (y, -SCM_MOST_NEGATIVE_FIXNUM) == 0)
         {
           /* Special case: x == fixnum-min && y == abs (fixnum-min) */
           scm_remember_upto_here_1 (y);
@@ -581,17 +580,17 @@ scm_integer_ceiling_quotient_iz (scm_t_inum x, SCM y)
 }
 
 SCM
-scm_integer_ceiling_quotient_zi (SCM x, scm_t_inum y)
+scm_integer_ceiling_quotient_zi (struct scm_bignum *x, scm_t_inum y)
 {
   if (y == 0)
     scm_num_overflow ("ceiling-quotient");
   else if (y == 1)
-    return x;
+    return scm_from_bignum (x);
   else
     {
       mpz_t q, zx;
       mpz_init (q);
-      alias_bignum_to_mpz (scm_bignum (x), zx);
+      alias_bignum_to_mpz (x, zx);
       if (y > 0)
         mpz_cdiv_q_ui (q, zx, y);
       else
@@ -605,12 +604,12 @@ scm_integer_ceiling_quotient_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_ceiling_quotient_zz (SCM x, SCM y)
+scm_integer_ceiling_quotient_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
   mpz_t q, zx, zy;
   mpz_init (q);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_cdiv_q (q, zx, zy);
   scm_remember_upto_here_2 (x, y);
   return take_mpz (q);
@@ -631,22 +630,22 @@ scm_integer_ceiling_remainder_ii (scm_t_inum x, 
scm_t_inum y)
 }
 
 SCM
-scm_integer_ceiling_remainder_iz (scm_t_inum x, SCM y)
+scm_integer_ceiling_remainder_iz (scm_t_inum x, struct scm_bignum *y)
 {
-  if (bignum_is_positive (scm_bignum (y)))
+  if (bignum_is_positive (y))
     {
       if (x > 0)
         {
           mpz_t r, zy;
           mpz_init (r);
-          alias_bignum_to_mpz (scm_bignum (y), zy);
+          alias_bignum_to_mpz (y, zy);
           mpz_sub_ui (r, zy, x);
           scm_remember_upto_here_1 (y);
           mpz_neg (r, r);
           return take_mpz (r);
         }
       else if (x == SCM_MOST_NEGATIVE_FIXNUM &&
-               bignum_cmp_long (scm_bignum (y), -SCM_MOST_NEGATIVE_FIXNUM) == 
0)
+               bignum_cmp_long (y, -SCM_MOST_NEGATIVE_FIXNUM) == 0)
         {
           /* Special case: x == fixnum-min && y == abs (fixnum-min) */
           scm_remember_upto_here_1 (y);
@@ -661,7 +660,7 @@ scm_integer_ceiling_remainder_iz (scm_t_inum x, SCM y)
     {
       mpz_t r, zy;
       mpz_init (r);
-      alias_bignum_to_mpz (scm_bignum (y), zy);
+      alias_bignum_to_mpz (y, zy);
       mpz_add_ui (r, zy, -x);
       scm_remember_upto_here_1 (y);
       mpz_neg (r, r);
@@ -670,14 +669,14 @@ scm_integer_ceiling_remainder_iz (scm_t_inum x, SCM y)
 }
 
 SCM
-scm_integer_ceiling_remainder_zi (SCM x, scm_t_inum y)
+scm_integer_ceiling_remainder_zi (struct scm_bignum *x, scm_t_inum y)
 {
   if (y == 0)
     scm_num_overflow ("ceiling-remainder");
   else
     {
       mpz_t zx;
-      alias_bignum_to_mpz (scm_bignum (x), zx);
+      alias_bignum_to_mpz (x, zx);
       scm_t_inum r;
       if (y > 0)
         r = -mpz_cdiv_ui (zx, y);
@@ -689,12 +688,12 @@ scm_integer_ceiling_remainder_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_ceiling_remainder_zz (SCM x, SCM y)
+scm_integer_ceiling_remainder_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
   mpz_t r, zx, zy;
   mpz_init (r);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_cdiv_r (r, zx, zy);
   scm_remember_upto_here_2 (x, y);
   return take_mpz (r);
@@ -727,15 +726,15 @@ scm_integer_ceiling_divide_ii (scm_t_inum x, scm_t_inum 
y, SCM *qp, SCM *rp)
 }
 
 void
-scm_integer_ceiling_divide_iz (scm_t_inum x, SCM y, SCM *qp, SCM *rp)
+scm_integer_ceiling_divide_iz (scm_t_inum x, struct scm_bignum *y, SCM *qp, 
SCM *rp)
 {
-  if (bignum_is_positive (scm_bignum (y)))
+  if (bignum_is_positive (y))
     {
       if (x > 0)
         {
           mpz_t r, zy;
           mpz_init (r);
-          alias_bignum_to_mpz (scm_bignum (y), zy);
+          alias_bignum_to_mpz (y, zy);
           mpz_sub_ui (r, zy, x);
           scm_remember_upto_here_1 (y);
           mpz_neg (r, r);
@@ -743,7 +742,7 @@ scm_integer_ceiling_divide_iz (scm_t_inum x, SCM y, SCM 
*qp, SCM *rp)
           *rp = take_mpz (r);
         }
       else if (x == SCM_MOST_NEGATIVE_FIXNUM &&
-               bignum_cmp_long (scm_bignum (y), -SCM_MOST_NEGATIVE_FIXNUM) == 
0)
+               bignum_cmp_long (y, -SCM_MOST_NEGATIVE_FIXNUM) == 0)
         {
           /* Special case: x == fixnum-min && y == abs (fixnum-min) */
           scm_remember_upto_here_1 (y);
@@ -765,7 +764,7 @@ scm_integer_ceiling_divide_iz (scm_t_inum x, SCM y, SCM 
*qp, SCM *rp)
     {
       mpz_t r, zy;
       mpz_init (r);
-      alias_bignum_to_mpz (scm_bignum (y), zy);
+      alias_bignum_to_mpz (y, zy);
       mpz_add_ui (r, zy, -x);
       scm_remember_upto_here_1 (y);
       mpz_neg (r, r);
@@ -775,7 +774,7 @@ scm_integer_ceiling_divide_iz (scm_t_inum x, SCM y, SCM 
*qp, SCM *rp)
 }
 
 void
-scm_integer_ceiling_divide_zi (SCM x, scm_t_inum y, SCM *qp, SCM *rp)
+scm_integer_ceiling_divide_zi (struct scm_bignum *x, scm_t_inum y, SCM *qp, 
SCM *rp)
 {
   if (y == 0)
     scm_num_overflow ("ceiling-divide");
@@ -784,7 +783,7 @@ scm_integer_ceiling_divide_zi (SCM x, scm_t_inum y, SCM 
*qp, SCM *rp)
       mpz_t q, r, zx;
       mpz_init (q);
       mpz_init (r);
-      alias_bignum_to_mpz (scm_bignum (x), zx);
+      alias_bignum_to_mpz (x, zx);
       if (y > 0)
         mpz_cdiv_qr_ui (q, r, zx, y);
       else
@@ -799,13 +798,13 @@ scm_integer_ceiling_divide_zi (SCM x, scm_t_inum y, SCM 
*qp, SCM *rp)
 }
 
 void
-scm_integer_ceiling_divide_zz (SCM x, SCM y, SCM *qp, SCM *rp)
+scm_integer_ceiling_divide_zz (struct scm_bignum *x, struct scm_bignum *y, SCM 
*qp, SCM *rp)
 {
   mpz_t q, r, zx, zy;
   mpz_init (q);
   mpz_init (r);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_cdiv_qr (q, r, zx, zy);
   scm_remember_upto_here_2 (x, y);
   *qp = take_mpz (q);
@@ -825,10 +824,10 @@ scm_integer_truncate_quotient_ii (scm_t_inum x, 
scm_t_inum y)
 }
 
 SCM
-scm_integer_truncate_quotient_iz (scm_t_inum x, SCM y)
+scm_integer_truncate_quotient_iz (scm_t_inum x, struct scm_bignum *y)
 {
   if (x == SCM_MOST_NEGATIVE_FIXNUM &&
-      bignum_cmp_long (scm_bignum (y), -SCM_MOST_NEGATIVE_FIXNUM) == 0)
+      bignum_cmp_long (y, -SCM_MOST_NEGATIVE_FIXNUM) == 0)
     {
       /* Special case: x == fixnum-min && y == abs (fixnum-min) */
       scm_remember_upto_here_1 (y);
@@ -839,17 +838,17 @@ scm_integer_truncate_quotient_iz (scm_t_inum x, SCM y)
 }
 
 SCM
-scm_integer_truncate_quotient_zi (SCM x, scm_t_inum y)
+scm_integer_truncate_quotient_zi (struct scm_bignum *x, scm_t_inum y)
 {
   if (y == 0)
     scm_num_overflow ("truncate-quotient");
   else if (y == 1)
-    return x;
+    return scm_from_bignum (x);
   else
     {
       mpz_t q, zx;
       mpz_init (q);
-      alias_bignum_to_mpz (scm_bignum (x), zx);
+      alias_bignum_to_mpz (x, zx);
       if (y > 0)
         mpz_tdiv_q_ui (q, zx, y);
       else
@@ -863,12 +862,12 @@ scm_integer_truncate_quotient_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_truncate_quotient_zz (SCM x, SCM y)
+scm_integer_truncate_quotient_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
   mpz_t q, zx, zy;
   mpz_init (q);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_tdiv_q (q, zx, zy);
   scm_remember_upto_here_2 (x, y);
   return take_mpz (q);
@@ -887,10 +886,10 @@ scm_integer_truncate_remainder_ii (scm_t_inum x, 
scm_t_inum y)
 }
 
 SCM
-scm_integer_truncate_remainder_iz (scm_t_inum x, SCM y)
+scm_integer_truncate_remainder_iz (scm_t_inum x, struct scm_bignum *y)
 {
   if (x == SCM_MOST_NEGATIVE_FIXNUM &&
-      bignum_cmp_long (scm_bignum (y), -SCM_MOST_NEGATIVE_FIXNUM) == 0)
+      bignum_cmp_long (y, -SCM_MOST_NEGATIVE_FIXNUM) == 0)
     {
       /* Special case: x == fixnum-min && y == abs (fixnum-min) */
       scm_remember_upto_here_1 (y);
@@ -901,14 +900,14 @@ scm_integer_truncate_remainder_iz (scm_t_inum x, SCM y)
 }
 
 SCM
-scm_integer_truncate_remainder_zi (SCM x, scm_t_inum y)
+scm_integer_truncate_remainder_zi (struct scm_bignum *x, scm_t_inum y)
 {
   if (y == 0)
     scm_num_overflow ("truncate-remainder");
   else
     {
       mpz_t zx;
-      alias_bignum_to_mpz (scm_bignum (x), zx);
+      alias_bignum_to_mpz (x, zx);
       scm_t_inum r = mpz_tdiv_ui (zx, (y > 0) ? y : -y) * mpz_sgn (zx);
       scm_remember_upto_here_1 (x);
       return SCM_I_MAKINUM (r);
@@ -916,12 +915,12 @@ scm_integer_truncate_remainder_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_truncate_remainder_zz (SCM x, SCM y)
+scm_integer_truncate_remainder_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
   mpz_t r, zx, zy;
   mpz_init (r);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_tdiv_r (r, zx, zy);
   scm_remember_upto_here_2 (x, y);
   return take_mpz (r);
@@ -942,10 +941,10 @@ scm_integer_truncate_divide_ii (scm_t_inum x, scm_t_inum 
y, SCM *qp, SCM *rp)
 }
 
 void
-scm_integer_truncate_divide_iz (scm_t_inum x, SCM y, SCM *qp, SCM *rp)
+scm_integer_truncate_divide_iz (scm_t_inum x, struct scm_bignum *y, SCM *qp, 
SCM *rp)
 {
   if (x == SCM_MOST_NEGATIVE_FIXNUM &&
-      bignum_cmp_long (scm_bignum (y), -SCM_MOST_NEGATIVE_FIXNUM) == 0)
+      bignum_cmp_long (y, -SCM_MOST_NEGATIVE_FIXNUM) == 0)
     {
       /* Special case: x == fixnum-min && y == abs (fixnum-min) */
       scm_remember_upto_here_1 (y);
@@ -960,7 +959,7 @@ scm_integer_truncate_divide_iz (scm_t_inum x, SCM y, SCM 
*qp, SCM *rp)
 }
 
 void
-scm_integer_truncate_divide_zi (SCM x, scm_t_inum y, SCM *qp, SCM *rp)
+scm_integer_truncate_divide_zi (struct scm_bignum *x, scm_t_inum y, SCM *qp, 
SCM *rp)
 {
   if (y == 0)
     scm_num_overflow ("truncate-divide");
@@ -968,7 +967,7 @@ scm_integer_truncate_divide_zi (SCM x, scm_t_inum y, SCM 
*qp, SCM *rp)
     {
       mpz_t q, zx;
       mpz_init (q);
-      alias_bignum_to_mpz (scm_bignum (x), zx);
+      alias_bignum_to_mpz (x, zx);
       scm_t_inum r;
       if (y > 0)
         r = mpz_tdiv_q_ui (q, zx, y);
@@ -985,13 +984,13 @@ scm_integer_truncate_divide_zi (SCM x, scm_t_inum y, SCM 
*qp, SCM *rp)
 }
 
 void
-scm_integer_truncate_divide_zz (SCM x, SCM y, SCM *qp, SCM *rp)
+scm_integer_truncate_divide_zz (struct scm_bignum *x, struct scm_bignum *y, 
SCM *qp, SCM *rp)
 {
   mpz_t q, r, zx, zy;
   mpz_init (q);
   mpz_init (r);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_tdiv_qr (q, r, zx, zy);
   scm_remember_upto_here_2 (x, y);
   *qp = take_mpz (q);
@@ -1074,24 +1073,24 @@ scm_integer_centered_quotient_ii (scm_t_inum x, 
scm_t_inum y)
 }
 
 SCM
-scm_integer_centered_quotient_iz (scm_t_inum x, SCM y)
+scm_integer_centered_quotient_iz (scm_t_inum x, struct scm_bignum *y)
 {
   return integer_centered_quotient_zz (long_to_bignum (x),
-                                       scm_bignum (y));
+                                       y);
 }
 
 SCM
-scm_integer_centered_quotient_zi (SCM x, scm_t_inum y)
+scm_integer_centered_quotient_zi (struct scm_bignum *x, scm_t_inum y)
 {
   if (y == 0)
     scm_num_overflow ("centered-quotient");
   else if (y == 1)
-    return x;
+    return scm_from_bignum (x);
   else
     {
       mpz_t q, zx;
       mpz_init (q);
-      alias_bignum_to_mpz (scm_bignum (x), zx);
+      alias_bignum_to_mpz (x, zx);
       scm_t_inum r;
       /* Arrange for r to initially be non-positive, because that
          simplifies the test to see if it is within the needed
@@ -1116,9 +1115,9 @@ scm_integer_centered_quotient_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_centered_quotient_zz (SCM x, SCM y)
+scm_integer_centered_quotient_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
-  return integer_centered_quotient_zz (scm_bignum (x), scm_bignum (y));
+  return integer_centered_quotient_zz (x, y);
 }
 
 static SCM
@@ -1193,17 +1192,17 @@ scm_integer_centered_remainder_ii (scm_t_inum x, 
scm_t_inum y)
 }
 
 SCM
-scm_integer_centered_remainder_iz (scm_t_inum x, SCM y)
+scm_integer_centered_remainder_iz (scm_t_inum x, struct scm_bignum *y)
 {
   return integer_centered_remainder_zz (long_to_bignum (x),
-                                        scm_bignum (y));
+                                        y);
 }
 
 SCM
-scm_integer_centered_remainder_zi (SCM x, scm_t_inum y)
+scm_integer_centered_remainder_zi (struct scm_bignum *x, scm_t_inum y)
 {
   mpz_t zx;
-  alias_bignum_to_mpz (scm_bignum (x), zx);
+  alias_bignum_to_mpz (x, zx);
 
   if (y == 0)
     scm_num_overflow ("centered-remainder");
@@ -1228,9 +1227,9 @@ scm_integer_centered_remainder_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_centered_remainder_zz (SCM x, SCM y)
+scm_integer_centered_remainder_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
-  return integer_centered_remainder_zz (scm_bignum (x), scm_bignum (y));
+  return integer_centered_remainder_zz (x, y);
 }
 
 static void
@@ -1316,20 +1315,20 @@ scm_integer_centered_divide_ii (scm_t_inum x, 
scm_t_inum y, SCM *qp, SCM *rp)
 }
 
 void
-scm_integer_centered_divide_iz (scm_t_inum x, SCM y, SCM *qp, SCM *rp)
+scm_integer_centered_divide_iz (scm_t_inum x, struct scm_bignum *y, SCM *qp, 
SCM *rp)
 {
-  integer_centered_divide_zz (long_to_bignum (x), scm_bignum (y), qp, rp);
+  integer_centered_divide_zz (long_to_bignum (x), y, qp, rp);
 }
 
 void
-scm_integer_centered_divide_zi (SCM x, scm_t_inum y, SCM *qp, SCM *rp)
+scm_integer_centered_divide_zi (struct scm_bignum *x, scm_t_inum y, SCM *qp, 
SCM *rp)
 {
   if (y == 0)
     scm_num_overflow ("centered-divide");
 
   mpz_t q, zx;
   mpz_init (q);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
+  alias_bignum_to_mpz (x, zx);
   scm_t_inum r;
 
   /* Arrange for r to initially be non-positive, because that
@@ -1360,9 +1359,9 @@ scm_integer_centered_divide_zi (SCM x, scm_t_inum y, SCM 
*qp, SCM *rp)
 }
 
 void
-scm_integer_centered_divide_zz (SCM x, SCM y, SCM *qp, SCM *rp)
+scm_integer_centered_divide_zz (struct scm_bignum *x, struct scm_bignum *y, 
SCM *qp, SCM *rp)
 {
-  integer_centered_divide_zz (scm_bignum (x), scm_bignum (y), qp, rp);
+  integer_centered_divide_zz (x, y, qp, rp);
 }
 
 static SCM
@@ -1433,22 +1432,22 @@ scm_integer_round_quotient_ii (scm_t_inum x, scm_t_inum 
y)
 }
 
 SCM
-scm_integer_round_quotient_iz (scm_t_inum x, SCM y)
+scm_integer_round_quotient_iz (scm_t_inum x, struct scm_bignum *y)
 {
-  return integer_round_quotient_zz (long_to_bignum (x), scm_bignum (y));
+  return integer_round_quotient_zz (long_to_bignum (x), y);
 }
 
 SCM
-scm_integer_round_quotient_zi (SCM x, scm_t_inum y)
+scm_integer_round_quotient_zi (struct scm_bignum *x, scm_t_inum y)
 {
   if (y == 0)
     scm_num_overflow ("round-quotient");
   if (y == 1)
-    return x;
+    return scm_from_bignum (x);
 
   mpz_t q, zx;
   mpz_init (q);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
+  alias_bignum_to_mpz (x, zx);
   scm_t_inum r;
   int needs_adjustment;
 
@@ -1476,33 +1475,32 @@ scm_integer_round_quotient_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_round_quotient_zz (SCM x, SCM y)
+scm_integer_round_quotient_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
-  SCM q, r, r2;
+  mpz_t q, r, zx, zy;
   int cmp, needs_adjustment;
 
-  /* Note that x might be small enough to fit into a
-     fixnum, so we must not let it escape into the wild */
-  q = scm_i_mkbig ();
-  r = scm_i_mkbig ();
-  r2 = scm_i_mkbig ();
+  mpz_init (q);
+  mpz_init (r);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
 
-  mpz_fdiv_qr (SCM_I_BIG_MPZ (q), SCM_I_BIG_MPZ (r),
-              SCM_I_BIG_MPZ (x), SCM_I_BIG_MPZ (y));
-  mpz_mul_2exp (SCM_I_BIG_MPZ (r2), SCM_I_BIG_MPZ (r), 1);  /* r2 = 2*r */
-  scm_remember_upto_here_2 (x, r);
+  mpz_fdiv_qr (q, r, zx, zy);
+  scm_remember_upto_here_1 (x);
+  mpz_mul_2exp (r, r, 1);  /* r = 2*r */
 
-  cmp = mpz_cmpabs (SCM_I_BIG_MPZ (r2), SCM_I_BIG_MPZ (y));
-  if (mpz_odd_p (SCM_I_BIG_MPZ (q)))
+  cmp = mpz_cmpabs (r, zy);
+  mpz_clear (r);
+  scm_remember_upto_here_1 (y);
+  if (mpz_odd_p (q))
     needs_adjustment = (cmp >= 0);
   else
     needs_adjustment = (cmp > 0);
-  scm_remember_upto_here_2 (r2, y);
 
   if (needs_adjustment)
-    mpz_add_ui (SCM_I_BIG_MPZ (q), SCM_I_BIG_MPZ (q), 1);
+    mpz_add_ui (q, q, 1);
 
-  return scm_i_normbig (q);
+  return take_mpz (q);
 }
 
 static SCM
@@ -1574,13 +1572,13 @@ scm_integer_round_remainder_ii (scm_t_inum x, 
scm_t_inum y)
 }
 
 SCM
-scm_integer_round_remainder_iz (scm_t_inum x, SCM y)
+scm_integer_round_remainder_iz (scm_t_inum x, struct scm_bignum *y)
 {
-  return integer_round_remainder_zz (long_to_bignum (x), scm_bignum (y));
+  return integer_round_remainder_zz (long_to_bignum (x), y);
 }
 
 SCM
-scm_integer_round_remainder_zi (SCM x, scm_t_inum y)
+scm_integer_round_remainder_zi (struct scm_bignum *x, scm_t_inum y)
 {
   if (y == 0)
     scm_num_overflow ("round-remainder");
@@ -1590,7 +1588,7 @@ scm_integer_round_remainder_zi (SCM x, scm_t_inum y)
   int needs_adjustment;
 
   mpz_init (q);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
+  alias_bignum_to_mpz (x, zx);
 
   if (y > 0)
     {
@@ -1616,9 +1614,9 @@ scm_integer_round_remainder_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_round_remainder_zz (SCM x, SCM y)
+scm_integer_round_remainder_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
-  return integer_round_remainder_zz (scm_bignum (x), scm_bignum (y));
+  return integer_round_remainder_zz (x, y);
 }
 
 static void
@@ -1694,20 +1692,20 @@ scm_integer_round_divide_ii (scm_t_inum x, scm_t_inum 
y, SCM *qp, SCM *rp)
 }
 
 void
-scm_integer_round_divide_iz (scm_t_inum x, SCM y, SCM *qp, SCM *rp)
+scm_integer_round_divide_iz (scm_t_inum x, struct scm_bignum *y, SCM *qp, SCM 
*rp)
 {
-  integer_round_divide_zz (long_to_bignum (x), scm_bignum (y), qp, rp);
+  integer_round_divide_zz (long_to_bignum (x), y, qp, rp);
 }
 
 void
-scm_integer_round_divide_zi (SCM x, scm_t_inum y, SCM *qp, SCM *rp)
+scm_integer_round_divide_zi (struct scm_bignum *x, scm_t_inum y, SCM *qp, SCM 
*rp)
 {
   if (y == 0)
     scm_num_overflow ("round-divide");
 
   mpz_t q, zx;
   mpz_init (q);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
+  alias_bignum_to_mpz (x, zx);
   scm_t_inum r;
   int needs_adjustment;
 
@@ -1739,9 +1737,9 @@ scm_integer_round_divide_zi (SCM x, scm_t_inum y, SCM 
*qp, SCM *rp)
 }
 
 void
-scm_integer_round_divide_zz (SCM x, SCM y, SCM *qp, SCM *rp)
+scm_integer_round_divide_zz (struct scm_bignum *x, struct scm_bignum *y, SCM 
*qp, SCM *rp)
 {
-  integer_round_divide_zz (scm_bignum (x), scm_bignum (y), qp, rp);
+  integer_round_divide_zz (x, y, qp, rp);
 }
 
 SCM
@@ -1795,25 +1793,27 @@ scm_integer_gcd_ii (scm_t_inum x, scm_t_inum y)
 }
 
 SCM
-scm_integer_gcd_zi (SCM x, scm_t_inum y)
+scm_integer_gcd_zi (struct scm_bignum *x, scm_t_inum y)
 {
   scm_t_bits result;
   if (y == 0)
-    return scm_abs (x);
+    return scm_integer_abs_z (x);
   if (y < 0)
     y = -y;
-  result = mpz_gcd_ui (NULL, SCM_I_BIG_MPZ (x), y);
+  mpz_t zx;
+  alias_bignum_to_mpz (x, zx);
+  result = mpz_gcd_ui (NULL, zx, y);
   scm_remember_upto_here_1 (x);
   return ulong_to_scm (result);
 }
 
 SCM
-scm_integer_gcd_zz (SCM x, SCM y)
+scm_integer_gcd_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
   mpz_t result, zx, zy;
   mpz_init (result);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_gcd (result, zx, zy);
   scm_remember_upto_here_2 (x, y);
   return take_mpz (result);
@@ -1831,25 +1831,25 @@ scm_integer_lcm_ii (scm_t_inum x, scm_t_inum y)
 }
 
 SCM
-scm_integer_lcm_zi (SCM x, scm_t_inum y)
+scm_integer_lcm_zi (struct scm_bignum *x, scm_t_inum y)
 {
   if (y == 0) return SCM_INUM0;
   if (y < 0) y = - y;
   mpz_t result, zx;
   mpz_init (result);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
+  alias_bignum_to_mpz (x, zx);
   mpz_lcm_ui (result, zx, y);
   scm_remember_upto_here_1 (x);
   return take_mpz (result);
 }
 
 SCM
-scm_integer_lcm_zz (SCM x, SCM y)
+scm_integer_lcm_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
   mpz_t result, zx, zy;
   mpz_init (result);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_lcm (result, zx, zy);
   scm_remember_upto_here_2 (x, y);
   /* shouldn't need to normalize b/c lcm of 2 bigs should be big */
@@ -1899,14 +1899,14 @@ scm_integer_logand_ii (scm_t_inum x, scm_t_inum y)
 }
 
 SCM
-scm_integer_logand_zi (SCM x, scm_t_inum y)
+scm_integer_logand_zi (struct scm_bignum *x, scm_t_inum y)
 {
   if (y == 0)
     return SCM_INUM0;
 
   mpz_t result, zx, zy;
   mpz_init (result);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
+  alias_bignum_to_mpz (x, zx);
   mpz_init_set_si (zy, y);
   mpz_and (result, zy, zx);
   scm_remember_upto_here_1 (x);
@@ -1915,12 +1915,12 @@ scm_integer_logand_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_logand_zz (SCM x, SCM y)
+scm_integer_logand_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
   mpz_t result, zx, zy;
   mpz_init (result);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_and (result, zx, zy);
   scm_remember_upto_here_2 (x, y);
   return take_mpz (result);
@@ -1933,14 +1933,14 @@ scm_integer_logior_ii (scm_t_inum x, scm_t_inum y)
 }
 
 SCM
-scm_integer_logior_zi (SCM x, scm_t_inum y)
+scm_integer_logior_zi (struct scm_bignum *x, scm_t_inum y)
 {
   if (y == 0)
-    return x;
+    return scm_from_bignum (x);
 
   mpz_t result, zx, zy;
   mpz_init (result);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
+  alias_bignum_to_mpz (x, zx);
   mpz_init_set_si (zy, y);
   mpz_ior (result, zy, zx);
   scm_remember_upto_here_1 (x);
@@ -1949,12 +1949,12 @@ scm_integer_logior_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_logior_zz (SCM x, SCM y)
+scm_integer_logior_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
   mpz_t result, zx, zy;
   mpz_init (result);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_ior (result, zy, zx);
   scm_remember_upto_here_2 (x, y);
   return take_mpz (result);
@@ -1967,11 +1967,11 @@ scm_integer_logxor_ii (scm_t_inum x, scm_t_inum y)
 }
 
 SCM
-scm_integer_logxor_zi (SCM x, scm_t_inum y)
+scm_integer_logxor_zi (struct scm_bignum *x, scm_t_inum y)
 {
   mpz_t result, zx, zy;
   mpz_init (result);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
+  alias_bignum_to_mpz (x, zx);
   mpz_init_set_si (zy, y);
   mpz_xor (result, zy, zx);
   scm_remember_upto_here_1 (x);
@@ -1980,12 +1980,12 @@ scm_integer_logxor_zi (SCM x, scm_t_inum y)
 }
 
 SCM
-scm_integer_logxor_zz (SCM x, SCM y)
+scm_integer_logxor_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
   mpz_t result, zx, zy;
   mpz_init (result);
-  alias_bignum_to_mpz (scm_bignum (x), zx);
-  alias_bignum_to_mpz (scm_bignum (y), zy);
+  alias_bignum_to_mpz (x, zx);
+  alias_bignum_to_mpz (y, zy);
   mpz_xor (result, zy, zx);
   scm_remember_upto_here_2 (x, y);
   return take_mpz (result);
@@ -1998,13 +1998,13 @@ scm_integer_logtest_ii (scm_t_inum x, scm_t_inum y)
 }
 
 int
-scm_integer_logtest_zi (SCM x, scm_t_inum y)
+scm_integer_logtest_zi (struct scm_bignum *x, scm_t_inum y)
 {
   return scm_is_eq (scm_integer_logand_zi (x, y), SCM_INUM0);
 }
 
 int
-scm_integer_logtest_zz (SCM x, SCM y)
+scm_integer_logtest_zz (struct scm_bignum *x, struct scm_bignum *y)
 {
   return scm_is_eq (scm_integer_logand_zz (x, y), SCM_INUM0);
 }
@@ -2020,10 +2020,10 @@ scm_integer_logbit_ui (unsigned long index, scm_t_inum 
n)
 }
 
 int
-scm_integer_logbit_uz (unsigned long index, SCM n)
+scm_integer_logbit_uz (unsigned long index, struct scm_bignum *n)
 {
   mpz_t zn;
-  alias_bignum_to_mpz (scm_bignum (n), zn);
+  alias_bignum_to_mpz (n, zn);
   int val = mpz_tstbit (zn, index);
   scm_remember_upto_here_1 (n);
   return val;
@@ -2036,11 +2036,11 @@ scm_integer_lognot_i (scm_t_inum n)
 }
 
 SCM
-scm_integer_lognot_z (SCM n)
+scm_integer_lognot_z (struct scm_bignum *n)
 {
   mpz_t result, zn;
   mpz_init (result);
-  alias_bignum_to_mpz (scm_bignum (n), zn);
+  alias_bignum_to_mpz (n, zn);
   mpz_com (result, zn);
   scm_remember_upto_here_1 (n);
   return take_mpz (result);
@@ -2134,12 +2134,12 @@ scm_integer_lsh_iu (scm_t_inum n, unsigned long count)
 }
 
 SCM
-scm_integer_lsh_zu (SCM n, unsigned long count)
+scm_integer_lsh_zu (struct scm_bignum *n, unsigned long count)
 {
   ASSERT (count > 0);
   mpz_t result, zn;
   mpz_init (result);
-  alias_bignum_to_mpz (scm_bignum (n), zn);
+  alias_bignum_to_mpz (n, zn);
   mpz_mul_2exp (result, zn, count);
   scm_remember_upto_here_1 (n);
   return take_mpz (result);
@@ -2158,12 +2158,12 @@ scm_integer_floor_rsh_iu (scm_t_inum n, unsigned long 
count)
 }
 
 SCM
-scm_integer_floor_rsh_zu (SCM n, unsigned long count)
+scm_integer_floor_rsh_zu (struct scm_bignum *n, unsigned long count)
 {
   ASSERT (count > 0);
   mpz_t result, zn;
   mpz_init (result);
-  alias_bignum_to_mpz (scm_bignum (n), zn);
+  alias_bignum_to_mpz (n, zn);
   mpz_fdiv_q_2exp (result, zn, count);
   scm_remember_upto_here_1 (n);
   return take_mpz (result);
@@ -2191,12 +2191,12 @@ scm_integer_round_rsh_iu (scm_t_inum n, unsigned long 
count)
 }
 
 SCM
-scm_integer_round_rsh_zu (SCM n, unsigned long count)
+scm_integer_round_rsh_zu (struct scm_bignum *n, unsigned long count)
 {
   ASSERT (count > 0);
   mpz_t q, zn;
   mpz_init (q);
-  alias_bignum_to_mpz (scm_bignum (n), zn);
+  alias_bignum_to_mpz (n, zn);
   mpz_fdiv_q_2exp (q, zn, count);
   if (mpz_tstbit (zn, count-1)
       && (mpz_odd_p (q) || mpz_scan1 (zn, 0) < count-1))
@@ -2232,10 +2232,10 @@ scm_integer_bit_extract_i (scm_t_inum n, unsigned long 
start,
 }
 
 SCM
-scm_integer_bit_extract_z (SCM n, unsigned long start, unsigned long bits)
+scm_integer_bit_extract_z (struct scm_bignum *n, unsigned long start, unsigned 
long bits)
 {
   mpz_t zn;
-  alias_bignum_to_mpz (scm_bignum (n), zn);
+  alias_bignum_to_mpz (n, zn);
 
   if (bits == 1)
     {
@@ -2274,11 +2274,11 @@ scm_integer_logcount_i (scm_t_inum n)
 }
 
 SCM
-scm_integer_logcount_z (SCM n)
+scm_integer_logcount_z (struct scm_bignum *n)
 {
   unsigned long count;
   mpz_t zn;
-  alias_bignum_to_mpz (scm_bignum (n), zn);
+  alias_bignum_to_mpz (n, zn);
   if (mpz_sgn (zn) >= 0)
     count = mpz_popcount (zn);
   else
diff --git a/libguile/integers.h b/libguile/integers.h
index 3955e5ea8..0ffe713a1 100644
--- a/libguile/integers.h
+++ b/libguile/integers.h
@@ -23,153 +23,123 @@
 
 #include "libguile/numbers.h"
 
+struct scm_bignum;
+
+static inline struct scm_bignum *
+scm_bignum (SCM x)
+{
+  if (!SCM_BIGP (x)) abort ();
+  return (struct scm_bignum *) SCM_UNPACK (x);
+}
+
 SCM_INTERNAL int scm_is_integer_odd_i (scm_t_inum i);
-SCM_INTERNAL int scm_is_integer_odd_z (SCM z);
+SCM_INTERNAL int scm_is_integer_odd_z (struct scm_bignum *z);
 
 SCM_INTERNAL SCM scm_integer_abs_i (scm_t_inum i);
-SCM_INTERNAL SCM scm_integer_abs_z (SCM z);
-
-SCM_INTERNAL SCM scm_integer_floor_quotient_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_floor_quotient_iz (scm_t_inum x, SCM y);
-SCM_INTERNAL SCM scm_integer_floor_quotient_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_floor_quotient_zz (SCM x, SCM y);
-
-SCM_INTERNAL SCM scm_integer_floor_remainder_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_floor_remainder_iz (scm_t_inum x, SCM y);
-SCM_INTERNAL SCM scm_integer_floor_remainder_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_floor_remainder_zz (SCM x, SCM y);
-
-SCM_INTERNAL void scm_integer_floor_divide_ii (scm_t_inum x, scm_t_inum y,
-                                               SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_floor_divide_iz (scm_t_inum x, SCM y,
-                                               SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_floor_divide_zi (SCM x, scm_t_inum y,
-                                               SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_floor_divide_zz (SCM x, SCM y,
-                                               SCM *qp, SCM *rp);
-
-SCM_INTERNAL SCM scm_integer_ceiling_quotient_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_ceiling_quotient_iz (scm_t_inum x, SCM y);
-SCM_INTERNAL SCM scm_integer_ceiling_quotient_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_ceiling_quotient_zz (SCM x, SCM y);
-
-SCM_INTERNAL SCM scm_integer_ceiling_remainder_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_ceiling_remainder_iz (scm_t_inum x, SCM y);
-SCM_INTERNAL SCM scm_integer_ceiling_remainder_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_ceiling_remainder_zz (SCM x, SCM y);
-
-SCM_INTERNAL void scm_integer_ceiling_divide_ii (scm_t_inum x, scm_t_inum y,
-                                                 SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_ceiling_divide_iz (scm_t_inum x, SCM y,
-                                                 SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_ceiling_divide_zi (SCM x, scm_t_inum y,
-                                                 SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_ceiling_divide_zz (SCM x, SCM y,
-                                                 SCM *qp, SCM *rp);
-
-SCM_INTERNAL SCM scm_integer_truncate_quotient_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_truncate_quotient_iz (scm_t_inum x, SCM y);
-SCM_INTERNAL SCM scm_integer_truncate_quotient_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_truncate_quotient_zz (SCM x, SCM y);
-
-SCM_INTERNAL SCM scm_integer_truncate_remainder_ii (scm_t_inum x, scm_t_inum 
y);
-SCM_INTERNAL SCM scm_integer_truncate_remainder_iz (scm_t_inum x, SCM y);
-SCM_INTERNAL SCM scm_integer_truncate_remainder_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_truncate_remainder_zz (SCM x, SCM y);
-
-SCM_INTERNAL void scm_integer_truncate_divide_ii (scm_t_inum x, scm_t_inum y,
-                                                  SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_truncate_divide_iz (scm_t_inum x, SCM y,
-                                                  SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_truncate_divide_zi (SCM x, scm_t_inum y,
-                                                  SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_truncate_divide_zz (SCM x, SCM y,
-                                                  SCM *qp, SCM *rp);
-
-SCM_INTERNAL SCM scm_integer_centered_quotient_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_centered_quotient_iz (scm_t_inum x, SCM y);
-SCM_INTERNAL SCM scm_integer_centered_quotient_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_centered_quotient_zz (SCM x, SCM y);
-
-SCM_INTERNAL SCM scm_integer_centered_remainder_ii (scm_t_inum x, scm_t_inum 
y);
-SCM_INTERNAL SCM scm_integer_centered_remainder_iz (scm_t_inum x, SCM y);
-SCM_INTERNAL SCM scm_integer_centered_remainder_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_centered_remainder_zz (SCM x, SCM y);
-
-SCM_INTERNAL void scm_integer_centered_divide_ii (scm_t_inum x, scm_t_inum y,
-                                                  SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_centered_divide_iz (scm_t_inum x, SCM y,
-                                                  SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_centered_divide_zi (SCM x, scm_t_inum y,
-                                                  SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_centered_divide_zz (SCM x, SCM y,
-                                                  SCM *qp, SCM *rp);
-
-SCM_INTERNAL SCM scm_integer_round_quotient_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_round_quotient_iz (scm_t_inum x, SCM y);
-SCM_INTERNAL SCM scm_integer_round_quotient_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_round_quotient_zz (SCM x, SCM y);
-
-SCM_INTERNAL SCM scm_integer_round_remainder_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_round_remainder_iz (scm_t_inum x, SCM y);
-SCM_INTERNAL SCM scm_integer_round_remainder_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_round_remainder_zz (SCM x, SCM y);
-
-SCM_INTERNAL void scm_integer_round_divide_ii (scm_t_inum x, scm_t_inum y,
-                                               SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_round_divide_iz (scm_t_inum x, SCM y,
-                                               SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_round_divide_zi (SCM x, scm_t_inum y,
-                                               SCM *qp, SCM *rp);
-SCM_INTERNAL void scm_integer_round_divide_zz (SCM x, SCM y,
-                                               SCM *qp, SCM *rp);
+SCM_INTERNAL SCM scm_integer_abs_z (struct scm_bignum *z);
+
+#define DECLARE_QUOTIENT_OPERATORS(stem)                                \
+  SCM_INTERNAL SCM scm_integer_##stem##_quotient_ii (scm_t_inum x,      \
+                                                     scm_t_inum y);     \
+  SCM_INTERNAL SCM scm_integer_##stem##_quotient_iz (scm_t_inum x,      \
+                                                     struct scm_bignum *y); \
+  SCM_INTERNAL SCM scm_integer_##stem##_quotient_zi (struct scm_bignum *x, \
+                                                     scm_t_inum y);     \
+  SCM_INTERNAL SCM scm_integer_##stem##_quotient_zz (struct scm_bignum *x, \
+                                                     struct scm_bignum *y);
+
+#define DECLARE_REMAINDER_OPERATORS(stem)                               \
+  SCM_INTERNAL SCM scm_integer_##stem##_remainder_ii (scm_t_inum x,     \
+                                                      scm_t_inum y);    \
+  SCM_INTERNAL SCM scm_integer_##stem##_remainder_iz (scm_t_inum x,     \
+                                                      struct scm_bignum *y); \
+  SCM_INTERNAL SCM scm_integer_##stem##_remainder_zi (struct scm_bignum *x, \
+                                                      scm_t_inum y);    \
+  SCM_INTERNAL SCM scm_integer_##stem##_remainder_zz (struct scm_bignum *x, \
+                                                      struct scm_bignum *y);
+
+#define DECLARE_DIVIDE_OPERATORS(stem)                                  \
+  SCM_INTERNAL void scm_integer_##stem##_divide_ii (scm_t_inum x,       \
+                                                    scm_t_inum y,       \
+                                                    SCM *qp, SCM *rp);  \
+  SCM_INTERNAL void scm_integer_##stem##_divide_iz (scm_t_inum x,       \
+                                                    struct scm_bignum *y, \
+                                                    SCM *qp, SCM *rp);  \
+  SCM_INTERNAL void scm_integer_##stem##_divide_zi (struct scm_bignum *x, \
+                                                    scm_t_inum y,       \
+                                                    SCM *qp, SCM *rp);  \
+  SCM_INTERNAL void scm_integer_##stem##_divide_zz (struct scm_bignum *x, \
+                                                    struct scm_bignum *y, \
+                                                    SCM *qp, SCM *rp);
+
+#define DECLARE_DIVISION_OPERATORS(stem)                                \
+  DECLARE_QUOTIENT_OPERATORS(stem);                                     \
+  DECLARE_REMAINDER_OPERATORS(stem);                                    \
+  DECLARE_DIVIDE_OPERATORS(stem)
+
+DECLARE_DIVISION_OPERATORS(floor);
+DECLARE_DIVISION_OPERATORS(ceiling);
+DECLARE_DIVISION_OPERATORS(truncate);
+DECLARE_DIVISION_OPERATORS(centered);
+DECLARE_DIVISION_OPERATORS(round);
 
 SCM_INTERNAL SCM scm_integer_gcd_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_gcd_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_gcd_zz (SCM x, SCM y);
+SCM_INTERNAL SCM scm_integer_gcd_zi (struct scm_bignum *x, scm_t_inum y);
+SCM_INTERNAL SCM scm_integer_gcd_zz (struct scm_bignum *x,
+                                     struct scm_bignum *y);
 
 SCM_INTERNAL SCM scm_integer_lcm_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_lcm_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_lcm_zz (SCM x, SCM y);
+SCM_INTERNAL SCM scm_integer_lcm_zi (struct scm_bignum *x, scm_t_inum y);
+SCM_INTERNAL SCM scm_integer_lcm_zz (struct scm_bignum *x,
+                                     struct scm_bignum *y);
 
 SCM_INTERNAL SCM scm_integer_logand_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_logand_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_logand_zz (SCM x, SCM y);
+SCM_INTERNAL SCM scm_integer_logand_zi (struct scm_bignum *x, scm_t_inum y);
+SCM_INTERNAL SCM scm_integer_logand_zz (struct scm_bignum *x,
+                                        struct scm_bignum *y);
 
 SCM_INTERNAL SCM scm_integer_logior_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_logior_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_logior_zz (SCM x, SCM y);
+SCM_INTERNAL SCM scm_integer_logior_zi (struct scm_bignum *x, scm_t_inum y);
+SCM_INTERNAL SCM scm_integer_logior_zz (struct scm_bignum *x,
+                                        struct scm_bignum *y);
 
 SCM_INTERNAL SCM scm_integer_logxor_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_logxor_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL SCM scm_integer_logxor_zz (SCM x, SCM y);
+SCM_INTERNAL SCM scm_integer_logxor_zi (struct scm_bignum *x, scm_t_inum y);
+SCM_INTERNAL SCM scm_integer_logxor_zz (struct scm_bignum *x,
+                                        struct scm_bignum *y);
 
 SCM_INTERNAL int scm_integer_logtest_ii (scm_t_inum x, scm_t_inum y);
-SCM_INTERNAL int scm_integer_logtest_zi (SCM x, scm_t_inum y);
-SCM_INTERNAL int scm_integer_logtest_zz (SCM x, SCM y);
+SCM_INTERNAL int scm_integer_logtest_zi (struct scm_bignum *x, scm_t_inum y);
+SCM_INTERNAL int scm_integer_logtest_zz (struct scm_bignum *x,
+                                         struct scm_bignum *y);
 
 SCM_INTERNAL int scm_integer_logbit_ui (unsigned long bit, scm_t_inum n);
-SCM_INTERNAL int scm_integer_logbit_uz (unsigned long bit, SCM n);
+SCM_INTERNAL int scm_integer_logbit_uz (unsigned long bit,
+                                        struct scm_bignum *n);
 
 SCM_INTERNAL SCM scm_integer_lognot_i (scm_t_inum n);
-SCM_INTERNAL SCM scm_integer_lognot_z (SCM n);
+SCM_INTERNAL SCM scm_integer_lognot_z (struct scm_bignum *n);
 
 SCM_INTERNAL SCM scm_integer_modulo_expt_nnn (SCM n, SCM k, SCM m);
 
 SCM_INTERNAL SCM scm_integer_lsh_iu (scm_t_inum n, unsigned long count);
-SCM_INTERNAL SCM scm_integer_lsh_zu (SCM n, unsigned long count);
+SCM_INTERNAL SCM scm_integer_lsh_zu (struct scm_bignum *n,
+                                     unsigned long count);
 SCM_INTERNAL SCM scm_integer_floor_rsh_iu (scm_t_inum n, unsigned long count);
-SCM_INTERNAL SCM scm_integer_floor_rsh_zu (SCM n, unsigned long count);
+SCM_INTERNAL SCM scm_integer_floor_rsh_zu (struct scm_bignum *n,
+                                           unsigned long count);
 SCM_INTERNAL SCM scm_integer_round_rsh_iu (scm_t_inum n, unsigned long count);
-SCM_INTERNAL SCM scm_integer_round_rsh_zu (SCM n, unsigned long count);
+SCM_INTERNAL SCM scm_integer_round_rsh_zu (struct scm_bignum *n,
+                                           unsigned long count);
 
 SCM_INTERNAL SCM scm_integer_bit_extract_i (scm_t_inum n, unsigned long start,
                                             unsigned long bits);
-SCM_INTERNAL SCM scm_integer_bit_extract_z (SCM n, unsigned long start,
+SCM_INTERNAL SCM scm_integer_bit_extract_z (struct scm_bignum *n,
+                                            unsigned long start,
                                             unsigned long bits);
 
 SCM_INTERNAL SCM scm_integer_logcount_i (scm_t_inum n);
-SCM_INTERNAL SCM scm_integer_logcount_z (SCM n);
+SCM_INTERNAL SCM scm_integer_logcount_z (struct scm_bignum *n);
 
 
 
diff --git a/libguile/numbers.c b/libguile/numbers.c
index 191e6e968..1a840e424 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -743,7 +743,7 @@ SCM_PRIMITIVE_GENERIC (scm_odd_p, "odd?", 1, 0, 0,
   if (SCM_I_INUMP (n))
     return scm_from_bool (scm_is_integer_odd_i (SCM_I_INUM (n)));
   else if (SCM_BIGP (n))
-    return scm_from_bool (scm_is_integer_odd_z (n));
+    return scm_from_bool (scm_is_integer_odd_z (scm_bignum (n)));
   else if (SCM_REALP (n))
     {
       double val = SCM_REAL_VALUE (n);
@@ -770,7 +770,7 @@ SCM_PRIMITIVE_GENERIC (scm_even_p, "even?", 1, 0, 0,
   if (SCM_I_INUMP (n))
     return scm_from_bool (!scm_is_integer_odd_i (SCM_I_INUM (n)));
   else if (SCM_BIGP (n))
-    return scm_from_bool (!scm_is_integer_odd_z (n));
+    return scm_from_bool (!scm_is_integer_odd_z (scm_bignum (n)));
   else if (SCM_REALP (n))
     {
       double val = SCM_REAL_VALUE (n);
@@ -932,7 +932,7 @@ SCM_PRIMITIVE_GENERIC (scm_abs, "abs", 1, 0, 0,
         return x;
     }
   else if (SCM_BIGP (x))
-    return scm_integer_abs_z (x);
+    return scm_integer_abs_z (scm_bignum (x));
   else if (SCM_FRACTIONP (x))
     {
       if (scm_is_false (scm_negative_p (SCM_FRACTION_NUMERATOR (x))))
@@ -1204,7 +1204,7 @@ SCM_PRIMITIVE_GENERIC (scm_floor_quotient, 
"floor-quotient", 2, 0, 0,
       if (SCM_I_INUMP (y))
         return scm_integer_floor_quotient_ii (SCM_I_INUM (x), SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_floor_quotient_iz (SCM_I_INUM (x), y);
+        return scm_integer_floor_quotient_iz (SCM_I_INUM (x), scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_floor_quotient (SCM_I_INUM (x), SCM_REAL_VALUE 
(y));
       else if (SCM_FRACTIONP (y))
@@ -1216,9 +1216,9 @@ SCM_PRIMITIVE_GENERIC (scm_floor_quotient, 
"floor-quotient", 2, 0, 0,
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        return scm_integer_floor_quotient_zi (x, SCM_I_INUM (y));
+        return scm_integer_floor_quotient_zi (scm_bignum (x), SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_floor_quotient_zz (x, y);
+        return scm_integer_floor_quotient_zz (scm_bignum (x), scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_floor_quotient
          (scm_i_big2dbl (x), SCM_REAL_VALUE (y));
@@ -1295,7 +1295,7 @@ SCM_PRIMITIVE_GENERIC (scm_floor_remainder, 
"floor-remainder", 2, 0, 0,
       if (SCM_I_INUMP (y))
         return scm_integer_floor_remainder_ii (SCM_I_INUM (x), SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_floor_remainder_iz (SCM_I_INUM (x), y);
+        return scm_integer_floor_remainder_iz (SCM_I_INUM (x), scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_floor_remainder (SCM_I_INUM (x),
                                               SCM_REAL_VALUE (y));
@@ -1308,9 +1308,9 @@ SCM_PRIMITIVE_GENERIC (scm_floor_remainder, 
"floor-remainder", 2, 0, 0,
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        return scm_integer_floor_remainder_zi (x, SCM_I_INUM (y));
+        return scm_integer_floor_remainder_zi (scm_bignum (x), SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_floor_remainder_zz (x, y);
+        return scm_integer_floor_remainder_zz (scm_bignum (x), scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_floor_remainder
          (scm_i_big2dbl (x), SCM_REAL_VALUE (y));
@@ -1413,7 +1413,7 @@ scm_floor_divide (SCM x, SCM y, SCM *qp, SCM *rp)
       if (SCM_I_INUMP (y))
         scm_integer_floor_divide_ii (SCM_I_INUM (x), SCM_I_INUM (y), qp, rp);
       else if (SCM_BIGP (y))
-        scm_integer_floor_divide_iz (SCM_I_INUM (x), y, qp, rp);
+        scm_integer_floor_divide_iz (SCM_I_INUM (x), scm_bignum (y), qp, rp);
       else if (SCM_REALP (y))
        scm_i_inexact_floor_divide (SCM_I_INUM (x), SCM_REAL_VALUE (y), qp, rp);
       else if (SCM_FRACTIONP (y))
@@ -1425,9 +1425,9 @@ scm_floor_divide (SCM x, SCM y, SCM *qp, SCM *rp)
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        scm_integer_floor_divide_zi (x, SCM_I_INUM (y), qp, rp);
+        scm_integer_floor_divide_zi (scm_bignum (x), SCM_I_INUM (y), qp, rp);
       else if (SCM_BIGP (y))
-        scm_integer_floor_divide_zz (x, y, qp, rp);
+        scm_integer_floor_divide_zz (scm_bignum (x), scm_bignum (y), qp, rp);
       else if (SCM_REALP (y))
        scm_i_inexact_floor_divide (scm_i_big2dbl (x), SCM_REAL_VALUE (y),
                                     qp, rp);
@@ -1511,7 +1511,7 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_quotient, 
"ceiling-quotient", 2, 0, 0,
       if (SCM_I_INUMP (y))
         return scm_integer_ceiling_quotient_ii (SCM_I_INUM (x), SCM_I_INUM 
(y));
       else if (SCM_BIGP (y))
-        return scm_integer_ceiling_quotient_iz (SCM_I_INUM (x), y);
+        return scm_integer_ceiling_quotient_iz (SCM_I_INUM (x), scm_bignum 
(y));
       else if (SCM_REALP (y))
        return scm_i_inexact_ceiling_quotient (SCM_I_INUM (x),
                                                SCM_REAL_VALUE (y));
@@ -1524,9 +1524,9 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_quotient, 
"ceiling-quotient", 2, 0, 0,
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        return scm_integer_ceiling_quotient_zi (x, SCM_I_INUM (y));
+        return scm_integer_ceiling_quotient_zi (scm_bignum (x), SCM_I_INUM 
(y));
       else if (SCM_BIGP (y))
-        return scm_integer_ceiling_quotient_zz (x, y);
+        return scm_integer_ceiling_quotient_zz (scm_bignum (x), scm_bignum 
(y));
       else if (SCM_REALP (y))
        return scm_i_inexact_ceiling_quotient
          (scm_i_big2dbl (x), SCM_REAL_VALUE (y));
@@ -1604,7 +1604,8 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_remainder, 
"ceiling-remainder", 2, 0, 0,
         return scm_integer_ceiling_remainder_ii (SCM_I_INUM (x),
                                                  SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_ceiling_remainder_iz (SCM_I_INUM (x), y);
+        return scm_integer_ceiling_remainder_iz (SCM_I_INUM (x),
+                                                 scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_ceiling_remainder (SCM_I_INUM (x),
                                                 SCM_REAL_VALUE (y));
@@ -1617,9 +1618,11 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_remainder, 
"ceiling-remainder", 2, 0, 0,
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        return scm_integer_ceiling_remainder_zi (x, SCM_I_INUM (y));
+        return scm_integer_ceiling_remainder_zi (scm_bignum (x),
+                                                 SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_ceiling_remainder_zz (x, y);
+        return scm_integer_ceiling_remainder_zz (scm_bignum (x),
+                                                 scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_ceiling_remainder
          (scm_i_big2dbl (x), SCM_REAL_VALUE (y));
@@ -1721,7 +1724,7 @@ scm_ceiling_divide (SCM x, SCM y, SCM *qp, SCM *rp)
       if (SCM_I_INUMP (y))
         scm_integer_ceiling_divide_ii (SCM_I_INUM (x), SCM_I_INUM (y), qp, rp);
       else if (SCM_BIGP (y))
-        scm_integer_ceiling_divide_iz (SCM_I_INUM (x), y, qp, rp);
+        scm_integer_ceiling_divide_iz (SCM_I_INUM (x), scm_bignum (y), qp, rp);
       else if (SCM_REALP (y))
        scm_i_inexact_ceiling_divide (SCM_I_INUM (x), SCM_REAL_VALUE (y), qp, 
rp);
       else if (SCM_FRACTIONP (y))
@@ -1733,9 +1736,9 @@ scm_ceiling_divide (SCM x, SCM y, SCM *qp, SCM *rp)
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        scm_integer_ceiling_divide_zi (x, SCM_I_INUM (y), qp, rp);
+        scm_integer_ceiling_divide_zi (scm_bignum (x), SCM_I_INUM (y), qp, rp);
       else if (SCM_BIGP (y))
-        scm_integer_ceiling_divide_zz (x, y, qp, rp);
+        scm_integer_ceiling_divide_zz (scm_bignum (x), scm_bignum (y), qp, rp);
       else if (SCM_REALP (y))
        scm_i_inexact_ceiling_divide (scm_i_big2dbl (x), SCM_REAL_VALUE (y),
                                       qp, rp);
@@ -1820,7 +1823,8 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_quotient, 
"truncate-quotient", 2, 0, 0,
         return scm_integer_truncate_quotient_ii (SCM_I_INUM (x),
                                                  SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_truncate_quotient_iz (SCM_I_INUM (x), y);
+        return scm_integer_truncate_quotient_iz (SCM_I_INUM (x),
+                                                 scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_truncate_quotient (SCM_I_INUM (x),
                                                 SCM_REAL_VALUE (y));
@@ -1833,9 +1837,11 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_quotient, 
"truncate-quotient", 2, 0, 0,
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        return scm_integer_truncate_quotient_zi (x, SCM_I_INUM (y));
+        return scm_integer_truncate_quotient_zi (scm_bignum (x),
+                                                 SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_truncate_quotient_zz (x, y);
+        return scm_integer_truncate_quotient_zz (scm_bignum (x),
+                                                 scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_truncate_quotient
          (scm_i_big2dbl (x), SCM_REAL_VALUE (y));
@@ -1913,7 +1919,8 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_remainder, 
"truncate-remainder", 2, 0, 0,
         return scm_integer_truncate_remainder_ii (SCM_I_INUM (x),
                                                   SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_truncate_remainder_iz (SCM_I_INUM (x), y);
+        return scm_integer_truncate_remainder_iz (SCM_I_INUM (x),
+                                                  scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_truncate_remainder (SCM_I_INUM (x),
                                                  SCM_REAL_VALUE (y));
@@ -1926,9 +1933,11 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_remainder, 
"truncate-remainder", 2, 0, 0,
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        return scm_integer_truncate_remainder_zi (x, SCM_I_INUM (y));
+        return scm_integer_truncate_remainder_zi (scm_bignum (x),
+                                                  SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_truncate_remainder_zz (x, y);
+        return scm_integer_truncate_remainder_zz (scm_bignum (x),
+                                                  scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_truncate_remainder
          (scm_i_big2dbl (x), SCM_REAL_VALUE (y));
@@ -2031,7 +2040,8 @@ scm_truncate_divide (SCM x, SCM y, SCM *qp, SCM *rp)
         scm_integer_truncate_divide_ii (SCM_I_INUM (x), SCM_I_INUM (y),
                                         qp, rp);
       else if (SCM_BIGP (y))
-        scm_integer_truncate_divide_iz (SCM_I_INUM (x), y, qp, rp);
+        scm_integer_truncate_divide_iz (SCM_I_INUM (x), scm_bignum (y),
+                                        qp, rp);
       else if (SCM_REALP (y))
        scm_i_inexact_truncate_divide (SCM_I_INUM (x), SCM_REAL_VALUE (y),
                                        qp, rp);
@@ -2044,9 +2054,9 @@ scm_truncate_divide (SCM x, SCM y, SCM *qp, SCM *rp)
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        scm_integer_truncate_divide_zi (x, SCM_I_INUM (y), qp, rp);
+        scm_integer_truncate_divide_zi (scm_bignum (x), SCM_I_INUM (y), qp, 
rp);
       else if (SCM_BIGP (y))
-        scm_integer_truncate_divide_zz (x, y, qp, rp);
+        scm_integer_truncate_divide_zz (scm_bignum (x), scm_bignum (y), qp, 
rp);
       else if (SCM_REALP (y))
        scm_i_inexact_truncate_divide (scm_i_big2dbl (x), SCM_REAL_VALUE (y),
                                        qp, rp);
@@ -2133,7 +2143,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quotient, 
"centered-quotient", 2, 0, 0,
         return scm_integer_centered_quotient_ii (SCM_I_INUM (x),
                                                  SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_centered_quotient_iz (SCM_I_INUM (x), y);
+        return scm_integer_centered_quotient_iz (SCM_I_INUM (x), scm_bignum 
(y));
       else if (SCM_REALP (y))
        return scm_i_inexact_centered_quotient (SCM_I_INUM (x),
                                                 SCM_REAL_VALUE (y));
@@ -2146,9 +2156,11 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quotient, 
"centered-quotient", 2, 0, 0,
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        return scm_integer_centered_quotient_zi (x, SCM_I_INUM (y));
+        return scm_integer_centered_quotient_zi (scm_bignum (x),
+                                                 SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_centered_quotient_zz (x, y);
+        return scm_integer_centered_quotient_zz (scm_bignum (x),
+                                                 scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_centered_quotient
          (scm_i_big2dbl (x), SCM_REAL_VALUE (y));
@@ -2231,7 +2243,8 @@ SCM_PRIMITIVE_GENERIC (scm_centered_remainder, 
"centered-remainder", 2, 0, 0,
         return scm_integer_centered_remainder_ii (SCM_I_INUM (x),
                                                   SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_centered_remainder_iz (SCM_I_INUM (x), y);
+        return scm_integer_centered_remainder_iz (SCM_I_INUM (x),
+                                                  scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_centered_remainder (SCM_I_INUM (x),
                                                  SCM_REAL_VALUE (y));
@@ -2244,9 +2257,11 @@ SCM_PRIMITIVE_GENERIC (scm_centered_remainder, 
"centered-remainder", 2, 0, 0,
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        return scm_integer_centered_remainder_zi (x, SCM_I_INUM (y));
+        return scm_integer_centered_remainder_zi (scm_bignum (x),
+                                                  SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_centered_remainder_zz (x, y);
+        return scm_integer_centered_remainder_zz (scm_bignum (x),
+                                                  scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_centered_remainder
          (scm_i_big2dbl (x), SCM_REAL_VALUE (y));
@@ -2355,7 +2370,7 @@ scm_centered_divide (SCM x, SCM y, SCM *qp, SCM *rp)
       if (SCM_I_INUMP (y))
         scm_integer_centered_divide_ii (SCM_I_INUM (x), SCM_I_INUM (y), qp, 
rp);
       else if (SCM_BIGP (y))
-        scm_integer_centered_divide_iz (SCM_I_INUM (x), y, qp, rp);
+        scm_integer_centered_divide_iz (SCM_I_INUM (x), scm_bignum (y), qp, 
rp);
       else if (SCM_REALP (y))
        scm_i_inexact_centered_divide (SCM_I_INUM (x), SCM_REAL_VALUE (y),
                                        qp, rp);
@@ -2368,9 +2383,9 @@ scm_centered_divide (SCM x, SCM y, SCM *qp, SCM *rp)
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        scm_integer_centered_divide_zi (x, SCM_I_INUM (y), qp, rp);
+        scm_integer_centered_divide_zi (scm_bignum (x), SCM_I_INUM (y), qp, 
rp);
       else if (SCM_BIGP (y))
-        scm_integer_centered_divide_zz (x, y, qp, rp);
+        scm_integer_centered_divide_zz (scm_bignum (x), scm_bignum (y), qp, 
rp);
       else if (SCM_REALP (y))
        scm_i_inexact_centered_divide (scm_i_big2dbl (x), SCM_REAL_VALUE (y),
                                        qp, rp);
@@ -2462,7 +2477,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, 
"round-quotient", 2, 0, 0,
       if (SCM_I_INUMP (y))
         return scm_integer_round_quotient_ii (SCM_I_INUM (x), SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_round_quotient_iz (SCM_I_INUM (x), y);
+        return scm_integer_round_quotient_iz (SCM_I_INUM (x), scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_round_quotient (SCM_I_INUM (x),
                                              SCM_REAL_VALUE (y));
@@ -2475,9 +2490,9 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, 
"round-quotient", 2, 0, 0,
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        return scm_integer_round_quotient_zi (x, SCM_I_INUM (y));
+        return scm_integer_round_quotient_zi (scm_bignum (x), SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_round_quotient_zz (x, y);
+        return scm_integer_round_quotient_zz (scm_bignum (x), scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_round_quotient
          (scm_i_big2dbl (x), SCM_REAL_VALUE (y));
@@ -2559,7 +2574,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_remainder, 
"round-remainder", 2, 0, 0,
       if (SCM_I_INUMP (y))
         return scm_integer_round_remainder_ii (SCM_I_INUM (x), SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_round_remainder_iz (SCM_I_INUM (x), y);
+        return scm_integer_round_remainder_iz (SCM_I_INUM (x), scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_round_remainder (SCM_I_INUM (x),
                                               SCM_REAL_VALUE (y));
@@ -2572,9 +2587,9 @@ SCM_PRIMITIVE_GENERIC (scm_round_remainder, 
"round-remainder", 2, 0, 0,
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        return scm_integer_round_remainder_zi (x, SCM_I_INUM (y));
+        return scm_integer_round_remainder_zi (scm_bignum (x), SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_round_remainder_zz (x, y);
+        return scm_integer_round_remainder_zz (scm_bignum (x), scm_bignum (y));
       else if (SCM_REALP (y))
        return scm_i_inexact_round_remainder
          (scm_i_big2dbl (x), SCM_REAL_VALUE (y));
@@ -2682,7 +2697,7 @@ scm_round_divide (SCM x, SCM y, SCM *qp, SCM *rp)
       if (SCM_I_INUMP (y))
         scm_integer_round_divide_ii (SCM_I_INUM (x), SCM_I_INUM (y), qp, rp);
       else if (SCM_BIGP (y))
-        scm_integer_round_divide_iz (SCM_I_INUM (x), y, qp, rp);
+        scm_integer_round_divide_iz (SCM_I_INUM (x), scm_bignum (y), qp, rp);
       else if (SCM_REALP (y))
        scm_i_inexact_round_divide (SCM_I_INUM (x), SCM_REAL_VALUE (y), qp, rp);
       else if (SCM_FRACTIONP (y))
@@ -2694,9 +2709,9 @@ scm_round_divide (SCM x, SCM y, SCM *qp, SCM *rp)
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        scm_integer_round_divide_zi (x, SCM_I_INUM (y), qp, rp);
+        scm_integer_round_divide_zi (scm_bignum (x), SCM_I_INUM (y), qp, rp);
       else if (SCM_BIGP (y))
-        scm_integer_round_divide_zz (x, y, qp, rp);
+        scm_integer_round_divide_zz (scm_bignum (x), scm_bignum (y), qp, rp);
       else if (SCM_REALP (y))
        scm_i_inexact_round_divide (scm_i_big2dbl (x), SCM_REAL_VALUE (y),
                                     qp, rp);
@@ -2789,7 +2804,7 @@ scm_gcd (SCM x, SCM y)
       if (SCM_I_INUMP (y))
         return scm_integer_gcd_ii (SCM_I_INUM (x), SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_gcd_zi (y, SCM_I_INUM (x));
+        return scm_integer_gcd_zi (scm_bignum (y), SCM_I_INUM (x));
       else if (SCM_REALP (y) && scm_is_integer (y))
         goto handle_inexacts;
       else
@@ -2798,9 +2813,9 @@ scm_gcd (SCM x, SCM y)
   else if (SCM_BIGP (x))
     {
       if (SCM_I_INUMP (y))
-        return scm_integer_gcd_zi (x, SCM_I_INUM (y));
+        return scm_integer_gcd_zi (scm_bignum (x), SCM_I_INUM (y));
       else if (SCM_BIGP (y))
-        return scm_integer_gcd_zz (x, y);
+        return scm_integer_gcd_zz (scm_bignum (x), scm_bignum (y));
       else if (SCM_REALP (y) && scm_is_integer (y))
         goto handle_inexacts;
       else
@@ -2851,7 +2866,7 @@ scm_lcm (SCM n1, SCM n2)
       if (SCM_I_INUMP (n2))
         return scm_integer_lcm_ii (SCM_I_INUM (n1), SCM_I_INUM (n2));
       else if (SCM_BIGP (n2))
-        return scm_integer_lcm_zi (n2, SCM_I_INUM (n1));
+        return scm_integer_lcm_zi (scm_bignum (n2), SCM_I_INUM (n1));
       else if (SCM_REALP (n2) && scm_is_integer (n2))
         goto handle_inexacts;
       else
@@ -2860,9 +2875,9 @@ scm_lcm (SCM n1, SCM n2)
   else if (SCM_LIKELY (SCM_BIGP (n1)))
     {
       if (SCM_I_INUMP (n2))
-        return scm_integer_lcm_zi (n1, SCM_I_INUM (n2));
+        return scm_integer_lcm_zi (scm_bignum (n1), SCM_I_INUM (n2));
       else if (SCM_BIGP (n2))
-        return scm_integer_lcm_zz (n1, n2);
+        return scm_integer_lcm_zz (scm_bignum (n1), scm_bignum (n2));
       else if (SCM_REALP (n2) && scm_is_integer (n2))
         goto handle_inexacts;
       else
@@ -2961,16 +2976,16 @@ SCM scm_logand (SCM n1, SCM n2)
       if (SCM_I_INUMP (n2))
         return scm_integer_logand_ii (SCM_I_INUM (n1), SCM_I_INUM (n2));
       else if (SCM_BIGP (n2))
-        return scm_integer_logand_zi (n2, SCM_I_INUM (n1));
+        return scm_integer_logand_zi (scm_bignum (n2), SCM_I_INUM (n1));
       else
        SCM_WRONG_TYPE_ARG (SCM_ARG2, n2);
     }
   else if (SCM_BIGP (n1))
     {
       if (SCM_I_INUMP (n2))
-        return scm_integer_logand_zi (n1, SCM_I_INUM (n2));
+        return scm_integer_logand_zi (scm_bignum (n1), SCM_I_INUM (n2));
       else if (SCM_BIGP (n2))
-        return scm_integer_logand_zz (n1, n2);
+        return scm_integer_logand_zz (scm_bignum (n1), scm_bignum (n2));
       else
        SCM_WRONG_TYPE_ARG (SCM_ARG2, n2);
     }
@@ -3019,16 +3034,16 @@ SCM scm_logior (SCM n1, SCM n2)
       if (SCM_I_INUMP (n2))
         return scm_integer_logior_ii (SCM_I_INUM (n1), SCM_I_INUM (n2));
       else if (SCM_BIGP (n2))
-        return scm_integer_logior_zi (n2, SCM_I_INUM (n1));
+        return scm_integer_logior_zi (scm_bignum (n2), SCM_I_INUM (n1));
       else
        SCM_WRONG_TYPE_ARG (SCM_ARG2, n2);
     }
   else if (SCM_BIGP (n1))
     {
       if (SCM_I_INUMP (n2))
-        return scm_integer_logior_zi (n1, SCM_I_INUM (n2));
+        return scm_integer_logior_zi (scm_bignum (n1), SCM_I_INUM (n2));
       else if (SCM_BIGP (n2))
-        return scm_integer_logior_zz (n1, n2);
+        return scm_integer_logior_zz (scm_bignum (n1), scm_bignum (n2));
       else
        SCM_WRONG_TYPE_ARG (SCM_ARG2, n2);
     }
@@ -3079,16 +3094,16 @@ SCM scm_logxor (SCM n1, SCM n2)
       if (SCM_I_INUMP (n2))
         return scm_integer_logxor_ii (SCM_I_INUM (n1), SCM_I_INUM (n2));
       else if (SCM_BIGP (n2))
-        return scm_integer_logxor_zi (n2, SCM_I_INUM (n1));
+        return scm_integer_logxor_zi (scm_bignum (n2), SCM_I_INUM (n1));
       else
        SCM_WRONG_TYPE_ARG (SCM_ARG2, n2);
     }
   else if (SCM_BIGP (n1))
     {
       if (SCM_I_INUMP (n2))
-        return scm_integer_logxor_zi (n1, SCM_I_INUM (n2));
+        return scm_integer_logxor_zi (scm_bignum (n1), SCM_I_INUM (n2));
       else if (SCM_BIGP (n2))
-        return scm_integer_logxor_zz (n1, n2);
+        return scm_integer_logxor_zz (scm_bignum (n1), scm_bignum (n2));
       else
        SCM_WRONG_TYPE_ARG (SCM_ARG2, n2);
     }
@@ -3117,16 +3132,19 @@ SCM_DEFINE (scm_logtest, "logtest", 2, 0, 0,
         return scm_from_bool (scm_integer_logtest_ii (SCM_I_INUM (j),
                                                       SCM_I_INUM (k)));
       else if (SCM_BIGP (k))
-        return scm_from_bool (scm_integer_logtest_zi (k, SCM_I_INUM (j)));
+        return scm_from_bool (scm_integer_logtest_zi (scm_bignum (k),
+                                                      SCM_I_INUM (j)));
       else
        SCM_WRONG_TYPE_ARG (SCM_ARG2, k);
     }
   else if (SCM_BIGP (j))
     {
       if (SCM_I_INUMP (k))
-        return scm_from_bool (scm_integer_logtest_zi (j, SCM_I_INUM (k)));
+        return scm_from_bool (scm_integer_logtest_zi (scm_bignum (j),
+                                                      SCM_I_INUM (k)));
       else if (SCM_BIGP (k))
-        return scm_from_bool (scm_integer_logtest_zz (j, k));
+        return scm_from_bool (scm_integer_logtest_zz (scm_bignum (j),
+                                                      scm_bignum (k)));
       else
        SCM_WRONG_TYPE_ARG (SCM_ARG2, k);
     }
@@ -3156,7 +3174,7 @@ SCM_DEFINE (scm_logbit_p, "logbit?", 2, 0, 0,
   if (SCM_I_INUMP (j))
     return scm_from_bool (scm_integer_logbit_ui (iindex, SCM_I_INUM (j)));
   else if (SCM_BIGP (j))
-    return scm_from_bool (scm_integer_logbit_uz (iindex, j));
+    return scm_from_bool (scm_integer_logbit_uz (iindex, scm_bignum (j)));
   else
     SCM_WRONG_TYPE_ARG (SCM_ARG2, j);
 }
@@ -3179,7 +3197,7 @@ SCM_DEFINE (scm_lognot, "lognot", 1, 0, 0,
   if (SCM_I_INUMP (n))
     return scm_integer_lognot_i (SCM_I_INUM (n));
   else if (SCM_BIGP (n))
-    return scm_integer_lognot_z (n);
+    return scm_integer_lognot_z (scm_bignum (n));
   else
     SCM_WRONG_TYPE_ARG (SCM_ARG1, n);
 }
@@ -3240,7 +3258,7 @@ lsh (SCM n, SCM count, const char *fn)
     scm_num_overflow (fn);
   if (SCM_I_INUMP (n))
     return scm_integer_lsh_iu (SCM_I_INUM (n), ucount);
-  return scm_integer_lsh_zu (n, ucount);
+  return scm_integer_lsh_zu (scm_bignum (n), ucount);
 }
 
 static SCM
@@ -3254,7 +3272,7 @@ floor_rsh (SCM n, SCM count)
     return n;
   if (SCM_I_INUMP (n))
     return scm_integer_floor_rsh_iu (SCM_I_INUM (n), ucount);
-  return scm_integer_floor_rsh_zu (n, ucount);
+  return scm_integer_floor_rsh_zu (scm_bignum (n), ucount);
 }
 
 static SCM
@@ -3268,7 +3286,7 @@ round_rsh (SCM n, SCM count)
     return n;
   if (SCM_I_INUMP (n))
     return scm_integer_round_rsh_iu (SCM_I_INUM (n), ucount);
-  return scm_integer_round_rsh_zu (n, ucount);
+  return scm_integer_round_rsh_zu (scm_bignum (n), ucount);
 }
 
 SCM_DEFINE (scm_ash, "ash", 2, 0, 0,
@@ -3361,7 +3379,7 @@ SCM_DEFINE (scm_bit_extract, "bit-extract", 3, 0, 0,
   if (SCM_I_INUMP (n))
     return scm_integer_bit_extract_i (SCM_I_INUM (n), istart, bits);
   else
-    return scm_integer_bit_extract_z (n, istart, bits);
+    return scm_integer_bit_extract_z (scm_bignum (n), istart, bits);
 }
 #undef FUNC_NAME
 
@@ -3385,7 +3403,7 @@ SCM_DEFINE (scm_logcount, "logcount", 1, 0, 0,
   if (SCM_I_INUMP (n))
     return scm_integer_logcount_i (SCM_I_INUM (n));
   else if (SCM_BIGP (n))
-    return scm_integer_logcount_z (n);
+    return scm_integer_logcount_z (scm_bignum (n));
   else
     SCM_WRONG_TYPE_ARG (SCM_ARG1, n);
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]