Floor function for rationals available?

Torbjörn Granlund tg at gmplib.org
Mon Jun 22 12:54:26 UTC 2015

Moritz Schmitt <moritz at schmi.tt> writes:

  	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?
You're right; we get it "wrong" for negative arguments.  

I suppose one could adjust for that case efficiently (in O(1) amortised
time): Iff the rational is negative and its denominator != 1, then
subtract 1 after the conversion.

Please encrypt, key id 0xC8601622

More information about the gmp-discuss mailing list