C++ std::remquo() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
<cmath>

Definition

In C++, std::remquo(x, y, &q) does two jobs in one call. It returns the IEEE remainder of x / y, the same value as std::remainder(). It also stores the whole-number quotient in the int that you give it.

The stored quotient only has to be correct in its sign and its last few bits (at least three). That is enough to find out which quarter turn an angle is in, which is why it is used in the code behind sin() and cos().

std::remquo() is declared in <cmath> and is part of the group Remainder, scale, and compare. These functions split a number, scale it by a power of two, find its remainder, or pick between two numbers. They work directly on the binary form of a double.

Syntax

Include <cmath> and call std::remquo. Start with these lines.

C++
int q;
double a = std::remquo(10.0, 3.0, &q);   // a = 1,  q = 3
double b = std::remquo(11.0, 3.0, &q);   // b = -1, q = 4
CallWhat it does
std::remquo(10.0, 3.0, &q)Returns 1 and stores 3 in q.
std::remquo(11.0, 3.0, &q)Returns -1 and stores 4 in q.
std::remquo(-10.0, 3.0, &q)Returns -1 and stores -3. The sign of q follows x / y.

The third argument is a pointer to an int, so write &q. The quotient is rounded to the nearest whole number, the same as in remainder().

Library declarations
C++
float       remquo(float x, float y, int* quo);
double      remquo(double x, double y, int* quo);
long double remquo(long double x, long double y, int* quo);

Parameters

ParameterDescription
xRequired. The dividend. It can be float, double, or long double.
yRequired. The divisor. It must not be zero.
quoRequired. A pointer to an int. It receives the sign and at least the lowest three bits of the whole quotient.

Return Value

Return ValueDescription
RemainderThe IEEE remainder x - n * y, between -|y|/2 and |y|/2.
NaNReturned when y is 0, or when x is infinity or NaN. The value of *quo is then unspecified.
*quoThe quotient n (sign and low bits). The sign matches the sign of x / y.

C++ Examples

Example 1 — Remainder and Quotient Together

Call remquo() and print both the returned remainder and the stored quotient.

C++
#include <cmath>
#include <iostream>

int main() {
    double pairs[][2] = {{10, 3}, {11, 3}, {-10, 3}};

    for (auto& p : pairs) {
        int q;
        double r = std::remquo(p[0], p[1], &q);
        std::cout << p[0] << " / " << p[1] << ": remainder " << r
                  << ", quotient " << q << '\n';
    }
    return 0;
}

How It Works

  1. The variable q is passed with & so that remquo() can write the quotient into it.
  2. 10 / 3 is 3.33, nearest 3, so the remainder is 1 and q is 3. For 11 / 3 it rounds to 4 and the remainder is -1.
  3. For -10 / 3 the quotient is -3.33, nearest -3, so q is -3 and the remainder is -1. The sign of q follows the sign of x / y.

Example 2 — Which Quarter Turn Is an Angle In

Divide an angle by a quarter turn (pi / 2). remquo() gives the angle inside the quarter and, from q, the quarter number.

C++
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numbers>

int main() {
    double quarter = std::numbers::pi / 2;

    std::cout << std::fixed << std::setprecision(4);
    for (double angle : {7.0, 2.0, 5.0}) {
        int q;
        double r = std::remquo(angle, quarter, &q);
        std::cout << "angle " << angle << ": quarters " << q
                  << ", quadrant " << (q & 3) << ", rest " << r << '\n';
    }
    return 0;
}

How It Works

  1. The divisor is a quarter turn, about 1.5708 radians. The remainder is the angle left over inside the closest quarter.
  2. 7.0 contains 4 quarters (4.46 rounded). q & 3 keeps only the lowest two bits, and 4 & 3 is 0, so the quadrant is 0 and the rest is 0.7168.
  3. 2.0 is 1.27 quarters, so q is 1 with 0.4292 left. 5.0 gives 3 quarters and 0.2876. The remainder can also be negative when the nearest quarter is above the angle.

Example 3 — How Ties Are Decided

When the quotient is exactly halfway, the nearest even whole number is used. See it with x / 2 for odd numbers.

C++
#include <cmath>
#include <iostream>

int main() {
    for (double x : {5.0, 7.0, -5.0}) {
        int q;
        double r = std::remquo(x, 2.0, &q);
        std::cout << x << " / 2: quotient " << q << ", remainder " << r
                  << ", check " << (q * 2.0 + r) << '\n';
    }
    return 0;
}

How It Works

  1. 5 / 2 is exactly 2.5, a tie. The even neighbour 2 is used, so q is 2 and the remainder is 5 - 4 = 1.
  2. 7 / 2 is 3.5. The even neighbour is 4, so q is 4 and the remainder is -1. For -5 / 2 the tie goes to -2, giving -1.
  3. The last number checks the formula q * y + remainder. It gives back the original x every time, which proves that the pair of results is consistent.

Frequently Asked Questions

std::remquo(x, y, &q) returns the same remainder as std::remainder(x, y), and also stores the quotient (its sign and at least the last 3 bits) in the int q.
The IEEE remainder of x / y. The quotient is stored through the third argument, with the sign of x / y and at least the lowest 3 bits.
It is mostly used inside math code, such as reducing an angle before sin() or cos(). The quotient tells you which quarter turn the angle was in, and the remainder is the angle inside it.
For huge numbers the quotient may not fit in an int. The standard only promises the sign and at least the lowest 3 bits, which is all that is needed for tasks like finding a quadrant.
Include <cmath> and write std::remquo(). That always works and picks the C++ overloads. The global name ::remquo often works too, but the standard does not promise it, and it may only take a double.

Next: rint()

Keep going through the <cmath> functions. Round using the current rounding mode.

rint() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful