From cd0362604b117133b49bb18596c59143dbf7d14f Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Tue, 21 Sep 2004 00:42:30 +0000 Subject: [PATCH] =?UTF-8?q?Include=20=20in=20numbers.h,=20not=20in?= =?UTF-8?q?=20numbers.c.=20(scm=5Fto=5Fmpz,=20scm=5Ffrom=5Fmpz):=20New.=20?= =?UTF-8?q?Thanks=20to=20Andreas=20V=C3=B6gele!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libguile/numbers.c | 18 +++++++++++++++++- libguile/numbers.h | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/libguile/numbers.c b/libguile/numbers.c index e14a93ebe..2c9a7ea6f 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -50,7 +50,6 @@ #include #include #include -#include #include "libguile/_scm.h" #include "libguile/feature.h" @@ -5680,6 +5679,23 @@ scm_is_unsigned_integer (SCM val, scm_t_uintmax min, scm_t_uintmax max) #endif +void +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)); + else + scm_wrong_type_arg_msg (NULL, 0, val, "exact integer"); +} + +SCM +scm_from_mpz (mpz_t val) +{ + return scm_i_mpz2num (val); +} + int scm_is_real (SCM val) { diff --git a/libguile/numbers.h b/libguile/numbers.h index 4e39a2cc1..f663e9e85 100644 --- a/libguile/numbers.h +++ b/libguile/numbers.h @@ -22,6 +22,8 @@ +#include + #include "libguile/__scm.h" #include "libguile/print.h" @@ -323,6 +325,10 @@ SCM_API SCM scm_from_uint64 (scm_t_uint64 x); #endif +SCM_API void scm_to_mpz (SCM x, mpz_t rop); +SCM_API SCM scm_from_mpz (mpz_t rop); + + /* The conversion functions for other types are aliased to the appropriate ones from above. We pick the right one based on the size of the type.