guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Forwarded patch for modular exponentiation support (GMP powm)


From: Kevin Ryde
Subject: Re: Forwarded patch for modular exponentiation support (GMP powm)
Date: Thu, 12 Feb 2004 09:44:21 +1000
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux)

Eric Hanchrow <address@hidden> writes:
>
> +static void
> +coerce_to_big(SCM in, mpz_t out)
> +{
> +  if (SCM_BIGP(in))
> +    mpz_set(out, SCM_I_BIG_MPZ(in));
> +  else if (SCM_INUMP(in))
> +    {
> +      mpz_set_si(out, SCM_INUM(in));

You could use mpz_init_set and mpz_init_set_si here rather than
separate mpz_init's.

> +      mpz_t inverted;
> +      mpz_init(inverted);
> +      if (!mpz_invert (inverted, SCM_I_BIG_MPZ(result), m_tmp))
> +        {
> +          mpz_clear(inverted);
> +          scm_num_overflow(FUNC_NAME);
> +        }
> +      mpz_set(SCM_I_BIG_MPZ(result), inverted);
> +      mpz_clear(inverted);

I'm pretty sure you don't need the extra mpz_t temporary here.  Just
tell mpz_invert to put the result straight into SCM_I_BIG_MPZ(result).

> +  mpz_clear(m_tmp);
> +  mpz_clear(k_tmp);
> +  mpz_clear(n_tmp);

I think you need this under the inversion failure too, to avoid a
memory leak.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]