Round a mpq_t number to the nearest integer

behnaz.bostanipour at epfl.ch behnaz.bostanipour at epfl.ch
Tue May 19 11:18:02 CEST 2009


Hello,
Thanks for your reply.
By rounding to the nearest integer I mean to add 1/2 to mpq
fraction(n/d),and taking the floor of the result.Is what you prpose
(i.e. dividing 2n+d by 2d with rounding towards -Infinity)
equivalent to this?
Thanks,
Kind regards,
B.



Quoting Paul Zimmermann <Paul.Zimmermann at loria.fr>:

>> Date: Sun, 17 May 2009 16:52:50 +0200
>> From: behnaz.bostanipour at epfl.ch
>>
>> Hello;
>> I have a number "a" of type mpq_t and I would like
>> to round it to the nearest integer.The result can be
>> of type mpz_t or another type.Is there any function
>> which can help me to do so or should I implement it
>> myself?
>> Thanks,
>> RGDS,
>> B.
>
> unfortunately, there is no division with round-to-nearest in mpz.
> A workaround is the following: if n/d is the mpq fraction, then
> divide 2n+d by 2d with rounding towards -Infinity.
>
> Paul Zimmermann
>
>




More information about the gmp-discuss mailing list