Bug in C++ interface (comparison between rational and double)

Marc Glisse marc.glisse at normalesup.org
Wed Jan 28 09:24:11 CET 2009

On Tue, 27 Jan 2009, Abramo Bagnara wrote:

> The comparison between mpz_class and double works fine with +inf and
> -inf, while the comparison between mpq_class and double gives a floating
> point exception, due to inappropriate mpq_set_d call in eval specialization.
> I see two way to fix this:
> 1) add support for comparison between mpq and double in C interface and
> use that in gmpxx.h
> 2) add infinity (and nan) check in comparison eval specializations in
> gmpxx.h
> IMHO 1) gives a more complete solution. If you want we're willing to
> write the (trivial) patch.

Some advantages of solution 2 (I am not saying I am in favor of 2, just 
mentionning them for completeness) are that the patch is small 
(if(isfinite(d)) current code; else return 0<d;), does not introduce any 
new interface, and has absolutely no impact on the code when compiled with 
g++ -ffinite-math-only.

It looks like comparison is the only operation where a Inf or NaN double 
makes sense in gmpxx (all the others return a gmp type, which can not 
represent Inf or NaN) (actually division by Inf could make sense too).

Just curious: what application do you have where it is useful to compare a 
gmp type to a non-finite double? (I am not questionning the usefulness of 
the feature request but genuinely interested)

Marc Glisse

PS: anybody notice on the gmplib webpage that the server migration should 
be complete in 9 months?

More information about the gmp-bugs mailing list