[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 54/85: scm_to_mpz uses integer lib
From: |
Andy Wingo |
Subject: |
[Guile-commits] 54/85: scm_to_mpz uses integer lib |
Date: |
Thu, 13 Jan 2022 03:40:22 -0500 (EST) |
wingo pushed a commit to branch main
in repository guile.
commit 9a91c20a551484f6a71bb35fa47b10f75f502c74
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Thu Jan 6 21:47:20 2022 +0100
scm_to_mpz uses integer lib
* libguile/integers.h:
* libguile/integers.c (scm_integer_to_mpz_z): New internal function.
* libguile/numbers.c (scm_to_mpz): Use new function.
---
libguile/integers.c | 9 +++++++++
libguile/integers.h | 3 ++-
libguile/numbers.c | 2 +-
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/libguile/integers.c b/libguile/integers.c
index f00885792..0ca799b9e 100644
--- a/libguile/integers.c
+++ b/libguile/integers.c
@@ -3035,3 +3035,12 @@ scm_integer_to_uint64_z (struct scm_bignum *z, uint64_t
*val)
{
return bignum_to_uint64 (z, val);
}
+
+void
+scm_integer_to_mpz_z (struct scm_bignum *z, mpz_t n)
+{
+ mpz_t zn;
+ alias_bignum_to_mpz (z, zn);
+ mpz_init_set (n, zn);
+ scm_remember_upto_here_1 (z);
+}
diff --git a/libguile/integers.h b/libguile/integers.h
index f8d150119..e48db1d17 100644
--- a/libguile/integers.h
+++ b/libguile/integers.h
@@ -32,7 +32,8 @@ scm_bignum (SCM x)
return (struct scm_bignum *) SCM_UNPACK (x);
}
-SCM_INTERNAL SCM scm_integer_from_mpz (mpz_srcptr mpz);
+SCM_INTERNAL SCM scm_integer_from_mpz (const mpz_t n);
+SCM_INTERNAL void scm_integer_to_mpz_z (struct scm_bignum *z, mpz_t n);
SCM_INTERNAL int scm_is_integer_odd_i (scm_t_inum i);
SCM_INTERNAL int scm_is_integer_odd_z (struct scm_bignum *z);
diff --git a/libguile/numbers.c b/libguile/numbers.c
index 10efb303a..330ea2cdd 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -7090,7 +7090,7 @@ scm_to_mpz (SCM val, mpz_t rop)
if (SCM_I_INUMP (val))
mpz_set_si (rop, SCM_I_INUM (val));
else if (SCM_BIGP (val))
- mpz_set (rop, SCM_I_BIG_MPZ (val));
+ scm_integer_to_mpz_z (scm_bignum (val), rop);
else
scm_wrong_type_arg_msg (NULL, 0, val, "exact integer");
}
- [Guile-commits] 15/85: Implement centered-divide with new integer lib, (continued)
- [Guile-commits] 15/85: Implement centered-divide with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 32/85: Integer library takes bignums via opaque struct pointer, Andy Wingo, 2022/01/13
- [Guile-commits] 38/85: Clean up <, reimplement in terms of integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 39/85: positive?, negative? use integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 41/85: Clean up scm_sum, Andy Wingo, 2022/01/13
- [Guile-commits] 43/85: Simplify scm_product, use integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 44/85: Remove support for allowing exact numbers to be divided by zero, Andy Wingo, 2022/01/13
- [Guile-commits] 45/85: Clean up scm_divide, Andy Wingo, 2022/01/13
- [Guile-commits] 46/85: Fix deprecated bit-count* when counting 0 bits, Andy Wingo, 2022/01/13
- [Guile-commits] 48/85: Reimplement scm_is_{un, }signed_integer for bignums, Andy Wingo, 2022/01/13
- [Guile-commits] 54/85: scm_to_mpz uses integer lib,
Andy Wingo <=
- [Guile-commits] 51/85: Reimplement scm_{to,from}_{int64,uint64}, Andy Wingo, 2022/01/13
- [Guile-commits] 52/85: Implement scm_{to,from}_wchar inline, Andy Wingo, 2022/01/13
- [Guile-commits] 58/85: Remove dead bignum frexp code from numbers.c, Andy Wingo, 2022/01/13
- [Guile-commits] 53/85: Remove unused conv-{u,}integer.i.c, Andy Wingo, 2022/01/13
- [Guile-commits] 63/85: Use scm_integer_to_double_z in numbers.c instead of big2dbl, Andy Wingo, 2022/01/13
- [Guile-commits] 66/85: Finish srfi-60 port off old scm mpz API, Andy Wingo, 2022/01/13
- [Guile-commits] 74/85: Less pessimal scm_integer_sub_zi, Andy Wingo, 2022/01/13
- [Guile-commits] 76/85: Avoid bignum clone in scm_integer_sub_zz, Andy Wingo, 2022/01/13
- [Guile-commits] 79/85: Optimize scm_integer_mul_ii, Andy Wingo, 2022/01/13
- [Guile-commits] 80/85: Optimize integer-expt for fixnums, Andy Wingo, 2022/01/13