bug-gmp
[Top][All Lists]
Advanced

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

mpz_powm crashes with modulus>2^2100000


From: Jens Kruse Andersen
Subject: mpz_powm crashes with modulus>2^2100000
Date: Wed, 12 Mar 2003 06:48:32 +0100

I am a new GMP user and new to MinGW and gcc. I have built GMP 4.1.2 under
Windows XP with MinGW and MSYS using "./configure --enable-fft" and "make" on
my Athlon XP with 256 MB ram.
Output from gcc -v: gcc version 3.2 (mingw special 20020817-1)
Output from uname -a:
MINGW32_NT-5.1 JENS-ATHLON-XP 1.0.8(0.46/3/2) 2002-12-09 07:58 i686 unknown
Output from ./config.guess: athlon-pc-mingw32
Output from ./configfsf.guess: i686-pc-mingw32

I am compiling and running my own program in a dos-box under Windows but
compiling and running under MinGW makes no difference.
My program crashed (Windows reported an error had occured and ended the
program) after 4 days computation involving the largest known non-Mersenne
prime 3*2^2145353+1. The crash happened just as mpz_powm was called for the
first time. The Windows error report starts:
Exception information
Code: 0xc00000fd       Flags: 0x00000000

The program worked fine on smaller primes. It seems 3*2^2145353+1 is too big
as modulus in mpz_powm. I wrote my own version of powm, calling the functions
mpz_mul and mpz_mod which appear to work fine at this size. I was able to
complete my computation from a restore file and hope the result can be
trusted. I think it is trustworthy because it included a positive Fermat prp
test on the known prime.
My original program is complicated but I can reproduce the error with the
following program for exponent>=2100000. mpz_powm_ui always works and is only
included to show that.

#include <stdio.h>
#include <gmp.h>
int main (void) {
  unsigned long exponent=2100000;
  mpz_t p,r,x;
  mpz_init(p);
  mpz_init(r);
  mpz_init(x);
  mpz_ui_pow_ui(p,2,exponent);
  mpz_add_ui(p,p,1);
  mpz_set_ui(r,3);
  printf("Calling mpz_powm_ui...");
  mpz_powm_ui(x,r,3,p);
  printf("Done. ");
  printf("Calling mpz_powm...");
  mpz_powm(x,r,r,p);
  printf("Done.");
  return 0;
}

/* This program always writes:
   "Calling mpz_powm_ui...Done. Calling mpz_powm...".
   It then crashes for exponent>=2100000.
   It ends without writing "Done." for exponent=2083000.
   It ends correctly after writing "Done." for exponent<2050000.
   The exact limits seem to vary. */

--
Jens Kruse Andersen






reply via email to

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