Behavior of operator% in C++ class wrapper

Kevin Ryde user42 at zip.com.au
Tue Feb 24 07:04:54 CET 2004


Décio Luiz Gazzoni Filho <decio at decpp.net> writes:
>
> but according to gmpxx.h, operator% 
> employs the function for mpz_tdiv_r() for division, and so a negative integer 
> modulo a positive integer returns a negative result. Is this apparent 
> inconsistency done on purpose?

Yes, this way the class % is the same as the native integer %.  The
C99 standard specifies "tdiv" style for the latter.

> And would it be possible to change operator%'s behavior?

Alas, that would be an incompatible change.  There may well be a place
for an mpz_mod, but operator% is not it.


More information about the gmp-discuss mailing list