English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ How to use the remquo() function and example

C++ Library Function <cmath>

C ++of the remquo() function calculates the numerator/the floating-point remainder of the denominator, and also stores the quotient in the pointer passed to it.

C ++of the remquo() function calculates the numerator/The floating-point remainder of the denominator (rounded to the nearest value). It also stores the quotient in the pointer passed to it. It returns the valuerestder()function with the same value.

remquo() prototype [from C ++ 11Standard begins]

double remquo(double x, double y, int* ); 
float remquo(float x, float y, int* );
long long remquo(long double x, long double y, int* );
double remquo(Type1 x, Type2 y, int* ); // additional overloaded for other arithmetic type combinations.

remquo() function accepts three parameters and returns a value of type double, float, or long double. This feature is available in<cmath>defined in the header file.

remquo() parameters

  • x: the value of the numerator.

  • y: the value of the denominator.

  • q: pointer to the object, internally used to store the quotient of the remainder as an int type value.

remquo() return value

remquo() function returns x / y's floating-point remainder (rounded to the nearest value). If the denominator y is zero, remquo() returns NaN (Not a Number).

Example1: remquo() in C ++How does it work?

#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 " << x << ""/" << y << " = " << result << endl;
    cout << "Quotient " << x << ""/" << y << " = " << q << endl << endl;
    x = -12.5;
    result = remquo(x, y, &q);
    cout << "Remainder " << x << ""/" << y << " = " << result << endl;
    cout << "Quotient " << x << ""/" << y << " = " << q << endl << endl;
    y = 0;
    result = remquo(x, y, &q);
    cout << "Remainder " << x << ""/" << y << " = " << result << endl;
    cout << "Quotient " << x << ""/" << y << " = " << q << endl << endl;
    
    return 0;
}

When running the program, the output is:

Remainder 12.5/2.2 = -0.7
Quotient 12.5/2.2 = 6
Remainder -12.5/2.2 = 0.7
Quotient -12.5/2.2 = -6
Remainder -12.5/0 = -nan
Quotient -12.5/0 = 0

Example2: remquo() function for different types of parameters

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int q;
    double x = 12.5
    int y = 10;
    
    result = remquo(x, y, &q);
    cout << "Remainder " << x << ""/" << y << " = " << result << endl;
    
    return 0;
}

When running the program, the output is:

Remainder 12.5/10 = 2.5
Quotient 12.5/10 = 1

C++ Library Function <cmath>