diff options
author | Andy Wingo <wingo@pobox.com> | 2021-12-19 10:45:12 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2022-01-13 09:37:16 +0100 |
commit | 459163fca16eacebefa463d514a9364e6adcb779 (patch) | |
tree | 53e0a48bb21615b0cd851f4c3294e2e55a13d0d4 /libguile/numbers.c | |
parent | 7e85ffa8221ccfba50aec93da284f61265454d2e (diff) | |
download | guile-459163fca16eacebefa463d514a9364e6adcb779.tar.gz |
Implement scm_logxor with new integer library
* libguile/integers.c (scm_integer_logxor_ii, scm_integer_logxor_zi)
(scm_integer_logxor_zz): New internal functions.
* libguile/integers.h: Declare the new internal functions.
* libguile/numbers.c (scm_logxor): Use new internal functions.
Diffstat (limited to 'libguile/numbers.c')
-rw-r--r-- | libguile/numbers.c | 36 |
1 files changed, 4 insertions, 32 deletions
diff --git a/libguile/numbers.c b/libguile/numbers.c index ae904647c..77b2e0753 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -3065,8 +3065,6 @@ SCM_DEFINE (scm_i_logxor, "logxor", 0, 2, 1, SCM scm_logxor (SCM n1, SCM n2) #define FUNC_NAME s_scm_logxor { - scm_t_inum nn1; - if (SCM_UNBNDP (n2)) { if (SCM_UNBNDP (n1)) @@ -3079,45 +3077,19 @@ SCM scm_logxor (SCM n1, SCM n2) if (SCM_I_INUMP (n1)) { - nn1 = SCM_I_INUM (n1); if (SCM_I_INUMP (n2)) - { - scm_t_inum nn2 = SCM_I_INUM (n2); - return SCM_I_MAKINUM (nn1 ^ nn2); - } + return scm_integer_logxor_ii (SCM_I_INUM (n1), SCM_I_INUM (n2)); else if (SCM_BIGP (n2)) - { - intbig: - { - SCM result_z = scm_i_mkbig (); - mpz_t nn1_z; - mpz_init_set_si (nn1_z, nn1); - mpz_xor (SCM_I_BIG_MPZ (result_z), nn1_z, SCM_I_BIG_MPZ (n2)); - scm_remember_upto_here_1 (n2); - mpz_clear (nn1_z); - return scm_i_normbig (result_z); - } - } + return scm_integer_logxor_zi (n2, SCM_I_INUM (n1)); else SCM_WRONG_TYPE_ARG (SCM_ARG2, n2); } else if (SCM_BIGP (n1)) { if (SCM_I_INUMP (n2)) - { - SCM_SWAP (n1, n2); - nn1 = SCM_I_INUM (n1); - goto intbig; - } + return scm_integer_logxor_zi (n1, SCM_I_INUM (n2)); else if (SCM_BIGP (n2)) - { - SCM result_z = scm_i_mkbig (); - mpz_xor (SCM_I_BIG_MPZ (result_z), - SCM_I_BIG_MPZ (n1), - SCM_I_BIG_MPZ (n2)); - scm_remember_upto_here_2 (n1, n2); - return scm_i_normbig (result_z); - } + return scm_integer_logxor_zz (n1, n2); else SCM_WRONG_TYPE_ARG (SCM_ARG2, n2); } |