Bill Allombert on Wed, 31 Jul 2002 19:07:20 +0200

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

min/max are macros.

On Fri, Jul 26, 2002 at 08:17:49PM -0400, Igor Schein wrote:
> Hi,
> ? galoisinit(x^4 + 5264*x^3 + 8034856*x^2 + 4205424384*x + 504485485632);
>   ***   prime too small in fixedfield.

The problem come from the fact that min and max are macro and that I forget
a (long) cast and the first operand was unsigned.

--- galconj.c	Wed Jul 31 20:14:56 2002
+++ src/basemath/galconj.c	Wed Jul 31 20:16:30 2002
@@ -1812,7 +1812,7 @@
   /*Now, we study the orders of the Frobenius elements*/
-  min_prime=n*max(BITS_IN_LONG-bfffo(n)-4,2);
+  min_prime=n*max((long)BITS_IN_LONG-bfffo(n)-4,2);
   plift = 0;
   nbmax = 8+(n>>1);
   nbtest = 0; karma = k_amoeba;

I do not like macros that evaluate several time theirs arguments.
This cause bugs and is not nice for GP2C.
I would like we replace max and min by inlined functions.
We will loose the type polymorphism, but maybe with relief.
The Linux kernel code use a complicated macro max3(a,b,type)
where `type' specify the type of the comparison. But the code
is GNU C specific, and not really neccessary for PARI/GP.

So in place we need 3 inlined functions:
long max(long,long);
double maxd(double,double);
ulong maxu(ulong,ulong);

max/min are used an hundred time in PARI. We need to fix each use of
them between non long operand. It is not too hard to do with cscope.

Any comment on the function's name ?