Bill Allombert on Thu, 10 Sep 2020 15:42:35 +0200


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

Re: gp2c question


On Thu, Sep 10, 2020 at 02:05:55PM +0100, John Cremona wrote:
> I have a gp function which I am running using gp2c.  In the function I
> have the lines
> 
> p = 20.0;
> a = random(p)*2 -1;
> 
> since I want a to be a random real in the balanced unit internal
> [-1,1].  (I hope that is correct gp:  ?random does not mention the
> possibility of an argument of type t_REAL, but ??random does.)
> 
> Both p and are declared in a my() statement as type real with
> my(p:real, a:real, ...). The second line above causes a warning from
> gp2c
> 
> Warning:MCq.gp:9: Assignement to a less precise type: real<-gen
> a=(random(p)*2)-1
> 
> Should I worry about that?    And surely the right and left hand sides
> have the same type anyway?

The issue is that gp2c currently does not know that random(real) is a
real, and it does not know that real*2 is a real either, because it uses
a rule 'real*int' and real*0 is not a real.

You can shut up the warning by adding an explicit cast:
a=((random(p)*2)-1):real

I will add the necessary data to PARI to shut up the warning.

Cheers,
Bill