mpq conversion to mpz: this method is reliable?

Julien D Arques acc.gccquestions at
Thu Mar 23 14:56:16 CET 2023

Usign the c++ interface to gmp.

Is the following code correct to round the current rational to a floored
integer? (eg 5.9999 => 5 and 5.0001 => 5 as well)

mpq_class mpq_var;
double a_double = 0.90;
mpq_var /= a_double;
mpq_var.get_num() = mpq_var;
mpq_var.get_den() = 1;

As it seems to work, is there any failure to expect / special cases to deal
with ?


More information about the gmp-discuss mailing list