December 2005
Beginner to intermediate
618 pages
20h 19m
English
imaxdiv
Performs integer division, returning quotient and remainder
#include <inttypes.h> imaxdiv_timaxdiv( intmax_tdividend, intmax_tdivisor);
The imaxdiv() function is
the same as either ldiv() or
lldiv(), depending on how many
bits wide the system’s largest integer type is. Accordingly, the
structure type of the return value, imaxdiv_t, is the same as either ldiv_t or lldiv_t.
intmax_t people = 110284, apples = 9043291;
imaxdiv_t share;
if ( people == 0 ) // Avoid dividing by zero.
printf( "There's no one here to take the apples.\n" ), return -1;
else
share =imaxdiv( apples, people );
printf( "If there are %ji of us and %ji apples,\n"
"each of us gets %ji, with %ji left over.\n",
people, apples, share.quot, share.rem );This example prints the following output:
If there are 110284 of us and 9091817 apples, each of us gets 82, with 3 left over.
The description under div() in this chapter;
the floating point functions remainder() and
remquo()
Read now
Unlock full access