Alessio Rocchi on Fri, 09 Dec 2005 21:07:19 +0100


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

Factoring and gcoeff()


Hi everybody.
Before beginning to explain my problem, i would really say thanks to Bill Alombert for all the (wonderful) help he gave me until now. Ok, let's go on: i can succesfully factor numbers using factor() function with libpari. I need now to insert all prime factors (and their exponents) into a long int array (long int*. I know that it would be really simpler to use Pari types, but i need to use just pure C long int pointers).
Well, I use (pseudo-)code like this:

typedef struct{
long int* factors;
long int* exps;
} Factors;

GEN F=factor(<number>);
long length=lg(F[1]);
//code for allocating Factors.factors[] and Factors.exps[]
for(int i=0; i<length; i++){
   Factors.factors[i]=itos(gcoeff(F, i, 1));
   Factors.exps[i]=itos(gcoeff(F, i, 2));
}

Compilation is succesful. I get a really bad Segmentation Fault at runtime.
Same thing does happen when i try to print out the factors with a standard printf() (something like printf("Got base^exp : %ld^%ld\n", itos(gcoeff(F, i, 1)), itos(gcoeff(F, i, 2)))).
How can i workaround this problem?
Thank you so much,
cheers
Alessio Rocchi