summaryrefslogtreecommitdiff
path: root/libguile/integers.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2022-01-07 11:18:48 +0100
committerAndy Wingo <wingo@pobox.com>2022-01-13 09:37:17 +0100
commita4524da8c1b5ce6407931e6fab8ffa727370a798 (patch)
tree77516dc58d4a5655393800907d0fbaa0d483bef8 /libguile/integers.c
parent0754dbf3e831ebaadcabf84b3f48012e1c8dbaef (diff)
downloadguile-a4524da8c1b5ce6407931e6fab8ffa727370a798.tar.gz
Simplify scm_exact_integer_quotient
* libguile/integers.h: * libguile/integers.c (scm_integer_exact_quotient_iz): New internal function. * libguile/numbers.c (scm_i_make_ratio): Simplify and enforce invariants. (scm_exact_integer_quotient): Use integer lib.
Diffstat (limited to 'libguile/integers.c')
-rw-r--r--libguile/integers.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libguile/integers.c b/libguile/integers.c
index f8a03266e..f6d33a21c 100644
--- a/libguile/integers.c
+++ b/libguile/integers.c
@@ -2939,6 +2939,20 @@ scm_integer_exact_quotient_ii (scm_t_inum n, scm_t_inum d)
return scm_integer_truncate_quotient_ii (n, d);
}
+SCM
+scm_integer_exact_quotient_iz (scm_t_inum n, struct scm_bignum *d)
+{
+ // There are only two fixnum numerators that are evenly divided by
+ // bignum denominators: 0, which is evenly divided 0 times by
+ // anything, and SCM_MOST_NEGATIVE_FIXNUM, which is evenly divided -1
+ // time by SCM_MOST_POSITIVE_FIXNUM+1.
+ if (n == 0)
+ return SCM_INUM0;
+ ASSERT (n == SCM_MOST_NEGATIVE_FIXNUM);
+ ASSERT (bignum_cmp_long (d, SCM_MOST_POSITIVE_FIXNUM + 1) == 0);
+ return SCM_I_MAKINUM (-1);
+}
+
/* Return the exact integer q such that n = q*d, for exact integers n
and d, where d is known in advance to divide n evenly (with zero
remainder). For large integers, this can be computed more