[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Recursion problem while using GMP
From: |
Emre Sevinc |
Subject: |
Recursion problem while using GMP |
Date: |
Tue, 17 Sep 2002 12:32:30 +0300 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.0) Gecko/20020530 |
Hi,
I have a problem with calling the same function within itself (even at
the first step)
when the the function includes one of the mpz_set functions. For example
look at my (dummy, just for problem demonstration) IsPrime function below:
int IsPrime(mpz_t N)
{
static int recursion = 0;
mpz_t R, R_1, Q, ROP, ONE, HUNDRED, temp2, ROP2;
... a few other variable declarations
mpf_t log_N;
... a few other variable declarations
mpz_init (temp2);
... a few other variable initializations
/*mpz_set_str (R, "2", 10);*/
/*mpz_set_ui(R, (unsigned int) 2);*/
/*mpz_set_str (ONE, "1", 10); */
printf("Recursion depth = %d\n", recursion);
if ( recursion > 5 )
{
return 1;
}
else
{
recursion++;
mpz_sub_ui(N, N, (unsigned int) 1);
IsPrime(N);
}
}
This version works without any problems and calls itself 5 times but if
I just comment out
one of the mpz_set functions and run the program receive :
0 [main] a 2636 open_stackdumpfile: Dumping stack trace to
a.exe.stackdump
Segmentation fault (core dumped)
However, as you may see another GMP library function like mpz_sub_ui
works without
any problems.
Is it impossible to use recursion when using the GMP mpz_set functions?
Am I doing
something wrong?
I need recursion, calling the same function within itself because of the
Indian Primality
algorithm includes a recursion in itself (5. line of the algorithm).
I'll be really glad if somebody out there can enlighten me.
Thanks in advance.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Recursion problem while using GMP,
Emre Sevinc <=