Behavior of operator% in C++ class wrapper
Décio Luiz Gazzoni Filho
decio at decpp.net
Sun Feb 22 19:46:18 CET 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello,
I've been developing some software with GMP's C++ class wrapper. I'm working
with integers modulo p, so I use operator% very frequently.
Now mpz_mod() always returns a nonnegative result (since it employs the
function mpz_fdiv_r() for division), 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? And would it be possible to change operator%'s
behavior? Because it precludes me from using operator== to check for
congruences directly -- I've caught a few bugs in my code related to that
already. And it generally makes things more difficult: for instance, there
are algorithms which only work with nonnegative representation (like the
binary segmentation method for multiplying polynomials), so for these I'm
forced to perform a conversion to nonnegative representation.
Thanks,
Décio
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAOTFBFXvAfvngkOIRAqQ7AJ0dLNpeUjPmxTx5iYTr5dQE25T7ZgCZAUFv
17LREc721rwSn++xRORnur0=
=U8Dm
-----END PGP SIGNATURE-----
More information about the gmp-discuss
mailing list