Floor function for rationals available?
Moritz Schmitt
moritz at schmi.tt
Mon Jun 22 12:17:04 UTC 2015
On Mon, Jun 22, 2015 at 01:41:37PM +0200, Torbjörn Granlund wrote:
>
> I am using GMP with C, and I am looking for a floor function for rationals,
> i.e., something like mpq_floor(). However, I can't seem to find it.
>
> You need mpz_set_q. If you then need to get this mpz type as an
> (intergral) mpq, you need to assign it back (possibly using the
> low-level functions operating on the numerator).
Thanks for the hint.
In the GMP documentation I found the entry
— Function: void mpz_set (mpz_t rop, const mpz_t op)
— Function: void mpz_set_ui (mpz_t rop, unsigned long int op)
— Function: void mpz_set_si (mpz_t rop, signed long int op)
— Function: void mpz_set_d (mpz_t rop, double op)
— Function: void mpz_set_q (mpz_t rop, const mpq_t op)
— Function: void mpz_set_f (mpz_t rop, const mpf_t op)
Set the value of rop from op.
mpz_set_d, mpz_set_q and mpz_set_f truncate op to make it an integer.
Since 'truncate' is not defined let me ask just to be very sure: mpz_set_q just
cuts of whatever comes after the comma, right? In particular, it is not the
floor function. Or am I misunderstanding something?
Thanks,
Moritz
More information about the gmp-discuss
mailing list