Reading through the C specs I found this function:
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 compute the same remainder as theremainder
functions. In the object pointed to by quo they store a value whose sign is the sign ofx/y
and whose magnitude is congruent modulo 2^n to the magnitude of the integral quotient ofx/y
, where n is an implementation-defined integer greater than or equal to 3.The
remquo
functions returnx
REMy
. Ify
is zero, the value stored in the object pointed to byquo
is unspecified and whether a domain error occurs or the functions return zero is implementation defined.
I understand what it returns, it returns fmod(x, y)
, but I don't understand the whole quo
part. Is it semantically equal to this?
*quo = (int) x/y;
*quo %= n; /* n implementation defined */
And my last question, for what could this function be useful?
A typical usage of remquo() is the reduction of trigonometry function arguments. The last 3 bits of the quotient would allow one to tell which semi-quadrant an angle resides in, after a reduction modulo Pi/4, and to convert the original trig call into another trig call over an angle within the [0,Pi/4) interval (the new trig function could be different). The latter is usually computed via a Pade approximation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With