In C, remquo() returns a remainder like remainder() and also writes a few low bits of the quotient into an int pointer. That helps when you need both leftover and direction information.
You pass x, y, and a pointer quo. The function returns the remainder as a double and stores a signed integer related to the quotient through quo. Include <math.h>.
Only some bits of the quotient are guaranteed (implementation-defined count, at least 3). Use them as a hint, not as a full integer division result.
Syntax
Pass dividend, divisor, and a pointer for quotient bits. Start with this call.
C
remquo(5.1, 3.0, &q);
Call
What it does
remquo(5.1, 3.0, &q);
Returns the remainder and stores quotient bits in q.
Include <math.h>. On GCC, link with -lm. quo must point to a valid int.
Library declarations
C
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);
Parameters
Parameter
Description
x
Required. The dividend.
y
Required. The divisor. It must not be 0.
quo
Required. Pointer to an int that receives some quotient bits (with sign).
Return Value
Return Value
Description
Remainder
Same style of remainder as remainder().
Via quo
Stores a signed value with low-order quotient bits.
C Examples
Example 1 — Basic Remainder and Quotient Bits
Call remquo and print both the remainder and the stored integer.
C
#include <stdio.h>
#include <math.h>
int main(void) {
int q = 0;
double r = remquo(5.1, 3.0, &q);
printf("remainder = %.1f\n", r);
printf("quo bits = %d\n", q);
return 0;
}
Output
remainder = -0.9
quo bits = 2
How It Works
Declare q. An int will receive quotient bits.
Call remquo. Pass the address with &q.
Read remainder. Same IEEE-style leftover as remainder.
Read q. Here the nearby quotient bits show 2.
Example 2 — Quotient Bits Keep a Sign
Negative inputs can flip the sign of the stored quotient information.