From b7b8c575762cde27b25cd32744e6d70829ee0d46 Mon Sep 17 00:00:00 2001 From: Kevin Ryde Date: Thu, 25 Mar 2004 21:51:39 +0000 Subject: [PATCH] (scm_modular_expt): Return a negative remainder for a negative divisor, the same as `modulo' does. --- libguile/numbers.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libguile/numbers.c b/libguile/numbers.c index d54d5d4c3..d411265f6 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -1626,6 +1626,10 @@ SCM_DEFINE (scm_modular_expt, "modulo-expt", 3, 0, 0, n_tmp, k_tmp, m_tmp); + + if (mpz_sgn (m_tmp) < 0 && mpz_sgn (SCM_I_BIG_MPZ (result)) != 0) + mpz_add (SCM_I_BIG_MPZ (result), SCM_I_BIG_MPZ (result), m_tmp); + cleanup: mpz_clear (m_tmp); mpz_clear (k_tmp);