Bill Allombert on Thu, 09 Jun 2005 16:18:37 +0200


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

Re: dumb question about rationals


On Thu, Jun 09, 2005 at 02:20:33PM +0200, Vincent Torri wrote:
> 
> Hello,
> 
> my program is almost working. But in some cases, i got the error message:
> 
> impossible assignment I-->S

This mean you try to convert (with itos) a PARI object to a C long
integer and either the object is not a PARI integer, or it is too large
to fit in a signed long.

> It occurs when i try to get the value of the denominator of a rational. 
> The rational type is 4 and the denominator type is 1.

Please use symbolic name for type (4=t_FRAC, 1=t_INT, etc.)

> When could this error appear ?

Probably somewhere where you use itos().

> Another question: What i do is the following :
> 
> 1) I allocate 2 arrays of GEN (with malloc), say t1, t2
> 2) I init the 2 arrays
> 3) I do my stuff (a loop) :
>   a) i fill t2 with modified values of t1
>   b) t1 = t2 (i do a loop on k : t1[k] = t2[k])
> 4) store the values of t1, at the end of the loop
> 5) I free the 2 arrays.
> 
> Could the problem above (it appears in step 4) arise from the fact that I 
> use allocated arrays and I'm doing step 3)b) ? Should I use PARI vector 
> instead of arrays 

Usually it is simpler to use PARI vector allocated in the stack
than using malloc, though there are exceptions.

If you do 
GEN *T=(GEN*)malloc(1000,sizeof(GEN))
for(i=0;i<1000;i++) T[i]=stoi(i)

then T is actually an array of pointer to objects stored in the PARI
stack. If you gerepile() the stack, T will not be updated and 
element of T will point to random data.

Cheers,
Bill.