Division fuctions
Marc Glisse
marc.glisse at inria.fr
Thu Apr 28 08:02:27 CEST 2011
On Thu, 28 Apr 2011, Dimitri wrote:
> I've just read http://gmplib.org/manual/Integer-Division.html and I don't
> understand why there is three cathegories of functions (cdiv, fdiv and tdiv).
> Maybe it's because of my bad english, but I can't understand what thoses
> sentences means.
Seems quite well explained to me, but in case, a different explanation:
when you divide 6/2, the result is 3, no problem. When you divide 5/2, the
answer would be 2.5, but we are working with integers, so we need to round
2.5 to an integer. If you look at the libc functions to do that, you have
ceil, floor and trunc. So gmp also provides 3 divisions, depending on the
type of rounding you want.
Several roundings are useful. With 5 socks, you can only make 2 pairs. But
you need 3 double-rooms to fit 5 people.
The third rounding only differs for negative numbers.
--
Marc Glisse
More information about the gmp-discuss
mailing list