Jens Schmidt on Wed, 08 Aug 2018 12:45:46 +0200


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

Re: Missing function declaration "diviu_rem" for older code


Am 08.08.2018, 10:08 schrieb Karim Belabas
<Karim.Belabas@math.u-bordeaux.fr>:

> * Jens Schmidt [2018-08-08 07:59]:
> > diviu_rem has been renamed to absdiviu_rem. Older Code will not
> > compile because there is no compatibility declaration to change
> > calls from diviu_rem to absdiviu_rem.
> > 
> > I thinks it's sufficient to add a declaration to pari/pariold.h.
> > This one liner would fix the problem:
> > 
> >   #define diviu_rem   absdiviu_rem  
> 
> You are right as far as backward compatibility is concerned: diviu_rem
> was introduced in 2.7, removed in 2.11, and the proposed #define will
> compile older code (intended for 2.7 or 2.9) with identical
> specifications.
> 
> However, omitting the #define in 2.11 was intentional. The problem
> with diviu_rem is that older code using it is likely to have been
> subtly broken: contrary to what happens in similar kernel functions
> of arity 2 (e.g. muliu, umodiu), the 'u' specifier changed the
> meaning of the *other* argument, i.e. diviu_rem(x, y, &r) performed
> the Euclidean division of abs(x) by y.
> 
> So everything is fine for x >= 0, but negative values will give
> "incorrect" results (but correct according to the old misguided
> specification in 2.7 and 2.9). I chose the least of two evils: user
> code breaks now, can be reviewed and possibly fixed in case it
> handled x < 0 incorrectly.  [ Same rationale for udiviu_rem and
> udivui_rem. ]
> 
> Cheers,
> 
>     K.B.
> 
> P.S. We may later introduce the now missing functions diviu_rem, diviu
> etc. with the expected specification (division of *x* by the 32-bit or
> 64-bit unsigned integer y). But it would have been even more confusing
> to do it now and have old code suddenly change behavior for x < 0 !
> 
> --

No problem. I solved the issue in a header of my own code:

  #if PARI_VERSION_CODE >= PARI_VERSION(2,11,0)
  # define diviu_rem   absdiviu_rem
  #endif


LG - Jens