mpq conversion to mpz: this method is reliable?

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


Hi,
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 ?


Thanks


More information about the gmp-discuss mailing list