unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Cc: guile-devel@gnu.org
Subject: Re: Forwarded patch for modular exponentiation support (GMP powm)
Date: Thu, 12 Feb 2004 09:44:21 +1000	[thread overview]
Message-ID: <87vfmdfaga.fsf@zip.com.au> (raw)
In-Reply-To: <87ad3qm76l.fsf@offby1.atm01.sea.blarg.net> (Eric Hanchrow's message of "Tue, 10 Feb 2004 23:00:50 -0800")

Eric Hanchrow <offby1@blarg.net> 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.


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


  reply	other threads:[~2004-02-11 23:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-28 17:22 Forwarded patch for modular exponentiation support (GMP powm) Rob Browning
2004-02-09 23:15 ` Kevin Ryde
2004-02-09 23:31   ` Kevin Ryde
     [not found]   ` <87llnah2hf.fsf@offby1.atm01.sea.blarg.net>
2004-02-11  1:02     ` Kevin Ryde
2004-02-11  7:00       ` Eric Hanchrow
2004-02-11 23:44         ` Kevin Ryde [this message]
2004-02-12  4:56           ` Eric Hanchrow
2004-02-14  0:23             ` Kevin Ryde
2004-02-15  0:04               ` Eric Hanchrow
2004-02-15 22:08                 ` Kevin Ryde
2004-03-20 21:20             ` Marius Vollmer
2004-03-20 21:32               ` Kevin Ryde
2004-03-21  2:28                 ` Marius Vollmer
2004-03-21 22:18                   ` Kevin Ryde
2004-03-22  0:01                     ` Eric Hanchrow
2004-03-22  0:37                       ` Kevin Ryde
2004-03-25  0:02                       ` Kevin Ryde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vfmdfaga.fsf@zip.com.au \
    --to=user42@zip.com.au \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).