December 2005
Beginner to intermediate
618 pages
20h 19m
English
remquo
Calculates the integer quotient and the remainder of a floating-point division
#include <math.h> doubleremquo( doublex, doubley, int *quo); floatremquof( floatx, floaty, int *quo); long doubleremquol( long doublex, long doubley, int *quo);
The remquo() functions are
similar to the remainder()
functions, except that they also store part of the integer quotient
of the division in the object referenced by the pointer argument.
The entire quotient may not fit in the int object referenced by the pointer, and
the ISO C standard requires only that the quotient as stored has the
same sign as the actual quotient
x/y, and that
its absolute value matches the actual quotient in at least the
lowest three bits, or modulo 8.
double apples = 0.0, people = 0.0, left = 0.0, share = 0.0;
int quotient = 0;
printf( "\nHow many people? ");
scanf( "%lf", &people );
printf( "\nHow many apples? ");
scanf( "%lf", &apples );
share = nearbyint( apples / people );
left =remquo( apples, people, "ient );
printf( "If there are %.2lf of us and %.2lf apples, "
"each of us gets %.2lf apple%s, with %.2lf left over.\n",
people, apples, share, ( share == 1 ) ? "" : "s", left );
printf( "remquo() stored %d as the quotient of the division (modulo 8).\n",
quotient );
printf( "Test: share modulo 8 − quotient = %d\n",
(int) share % 8 − quotient );Read now
Unlock full access