Previous Page
Next Page

remquo

Calculates the integer quotient and the remainder of a floating-point division

#include <math.h>
double remquo ( double x , double y , int *quo  );
float remquof ( float x , float y , int *quo  );
long double remquol ( long double x , long double y , 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.

Example

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, &quotient );

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 );

See Also

remainder( ), modf( )


Previous Page
Next Page