1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00

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.
This commit is contained in:
Andy Wingo 2022-01-06 21:47:20 +01:00
parent debcccc215
commit 9a91c20a55
3 changed files with 12 additions and 2 deletions

View file

@ -3035,3 +3035,12 @@ scm_integer_to_uint64_z (struct scm_bignum *z, uint64_t *val)
{ {
return bignum_to_uint64 (z, 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);
}

View file

@ -32,7 +32,8 @@ scm_bignum (SCM x)
return (struct scm_bignum *) SCM_UNPACK (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_i (scm_t_inum i);
SCM_INTERNAL int scm_is_integer_odd_z (struct scm_bignum *z); SCM_INTERNAL int scm_is_integer_odd_z (struct scm_bignum *z);

View file

@ -7090,7 +7090,7 @@ scm_to_mpz (SCM val, mpz_t rop)
if (SCM_I_INUMP (val)) if (SCM_I_INUMP (val))
mpz_set_si (rop, SCM_I_INUM (val)); mpz_set_si (rop, SCM_I_INUM (val));
else if (SCM_BIGP (val)) else if (SCM_BIGP (val))
mpz_set (rop, SCM_I_BIG_MPZ (val)); scm_integer_to_mpz_z (scm_bignum (val), rop);
else else
scm_wrong_type_arg_msg (NULL, 0, val, "exact integer"); scm_wrong_type_arg_msg (NULL, 0, val, "exact integer");
} }