Karim Belabas on Wed, 08 Aug 2018 10:53:08 +0200


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

Re: Missing function declaration "diviu_rem" for older code


* 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 !

--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite de Bordeaux         Fax: (+33) (0)5 40 00 21 23
351, cours de la Liberation    http://www.math.u-bordeaux.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]
`