remquo()
The remquo()
function returns the remainder of two integer values, and stores an integer value with the sign and approximate magnitude of the quotient in a parameter.
Syntax
remquo(numerator, denominator, int* quotient)
The data type of the return value will either be a double
, float
, or long double
. Combinations of these types will return a double
. The parameter quotient
must always be an int
pointer.
The remquo()
function calculates the floating-point remainder f
of numerator / denominator
such that numerator = n * denominator + f*
, where n is an integer, f
has the same sign as numerator
, and the absolute value of f
is less than the absolute value of denominator
.
Example
The following example uses the remquo()
function to calculate the remainders and quotients of multiple values:
#include <iostream>#include <cmath>using namespace std;int main() {int q;double x = 12.5, y = 2.2;double result = remquo(x, y, &q);cout << "Remainder of " << x << "/" << y << " = " << result << endl;cout << "Quotient of " << x << "/" << y << " = " << q << endl << endl;x = -12.5;result = remquo(x, y, &q);cout << "Remainder of " << x << "/" << y << " = " << result << endl;cout << "Quotient of " << x << "/" << y << " = " << q << endl << endl;y = 0;result = remquo(x, y, &q);cout << "Remainder of " << x << "/" << y << " = " << result << endl;cout << "Quotient of " << x << "/" << y << " = " << q << endl << endl;return 0;}
This produces the following output:
Remainder of 12.5/2.2 = -0.7Quotient of 12.5/2.2 = 6Remainder of -12.5/2.2 = 0.7Quotient of -12.5/2.2 = -6Remainder of -12.5/0 = -nanQuotient of -12.5/0 = 0
Codebyte Example
The following example is runnable and uses the remquo()
function to return the remainder and quotient of 12.5 / 10
:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.