inf & nan for mpq

Nic Schraudolph nic at
Wed Nov 17 10:16:05 CET 2010

> If you have found any bugs in GMP, then please report them to the gmp-bugs mailing list

I don't think that would be appropriate. From the GMP docs (emphasis mine):

All rational arithmetic functions assume operands have a canonical
form, and canonicalize their result.  The canonical from means that the
denominator and the numerator have no common factors, and that the
*denominator is positive*.  Zero has the unique representation 0/1.

In other words, zero denominators are not in canonical form by the current definition, so the behavior of mpq functions on them is not defined. I've taken the fact that not even mpq_set_* guard against zero denominators as pretty solid confirmation that they're simply outside the present scope of applicability of mpq.

If you want to extend that scope so that mpq behaves in some well-defined manner for zero denominators, just create 1/0 and 0/0 mpq's, run them through the mpq_* functions and observe/fix what's not to your liking. Half a year ago I could have told you exactly which functions do what for zero denominators; unfortunately now (one hard disk crash & incomplete backup later) that list's gone the way of the dodo.

> Your patch is not the solution to such bugs, and fixing bugs will take
> priority over considering any feature patch.

If a new feature improves functionality to such an extent that the previous behavior now appears buggy, some might take that as an indication of its worth... but your priorities are your business.

- nic

More information about the gmp-discuss mailing list