diff options
author | Andy Wingo <wingo@pobox.com> | 2021-12-19 10:13:42 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2022-01-13 09:37:16 +0100 |
commit | 7e85ffa8221ccfba50aec93da284f61265454d2e (patch) | |
tree | cf432a09bc35928350044c26361edaad2bb690f4 /libguile/integers.c | |
parent | 4a380aa6ac331500faf52a2c599abac06dd7855b (diff) | |
download | guile-7e85ffa8221ccfba50aec93da284f61265454d2e.tar.gz |
Implement scm_logior with new integer library
* libguile/integers.c (scm_integer_logior_ii, scm_integer_logior_zi)
(scm_integer_logior_zz): New internal functions.
* libguile/integers.h: Declare the new internal functions.
* libguile/numbers.c (scm_logior): Use new internal functions.
Diffstat (limited to 'libguile/integers.c')
-rw-r--r-- | libguile/integers.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libguile/integers.c b/libguile/integers.c index eb65ed221..816a49d93 100644 --- a/libguile/integers.c +++ b/libguile/integers.c @@ -1924,3 +1924,37 @@ scm_integer_logand_zz (SCM x, SCM y) scm_remember_upto_here_2 (x, y); return take_mpz (result); } + +SCM +scm_integer_logior_ii (scm_t_inum x, scm_t_inum y) +{ + return SCM_I_MAKINUM (x | y); +} + +SCM +scm_integer_logior_zi (SCM x, scm_t_inum y) +{ + if (y == 0) + return x; + + mpz_t result, zx, zy; + mpz_init (result); + alias_bignum_to_mpz (scm_bignum (x), zx); + mpz_init_set_si (zy, y); + mpz_ior (result, zy, zx); + scm_remember_upto_here_1 (x); + mpz_clear (zy); + return take_mpz (result); +} + +SCM +scm_integer_logior_zz (SCM x, SCM 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); + mpz_ior (result, zy, zx); + scm_remember_upto_here_2 (x, y); + return take_mpz (result); +} |