Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
c++

What is the remquo() function in C++?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The remquo() function in C++ computes the floating point remainder of two arguments (x, y) passed to it. It also saves the quotient to the pointer (z) passed to it.

Syntax

double remquo(double x, double y, int* q); 
float remquo(float x, float y, int* q);
long double remquo(long double x, long double y, int* q);

Parameter values

The remquo() function takes three parameter values:

  • x: This represents the numerator.
  • y: This represents the denominator.
  • z: This represents the pointer to an object where the remainder is stored as an integer value type.

Return value

The remquo() function returns a floating point remainder of the fraction x/y. When the denominator given is 0, the function returns NaN (i.e., Not a Number).

Example

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int z;
double x = 12.5, y = 2.2;
double result = remquo(x, y, &z);
cout << "Remainder of " << x << "/" << y << " = " << result << endl;
cout << "Quotient of " << x << "/" << y << " = " << z << endl << endl;
x = -12.5;
result = remquo(x, y, &z);
cout << "Remainder of " << x << "/" << y << " = " << result << endl;
cout << "Quotient of " << x << "/" << y << " = " << z << endl << endl;
y = 0;
result = remquo(x, y, &z);
cout << "Remainder of " << x << "/" << y << " = " << result << endl;
cout << "Quotient of " << x << "/" << y << " = " << z << endl << endl;
return 0;
}
Implementing the remquo() function

Code explanation

  • Line 8: We create an integer variable, z. It serves as the pointer parameter in our program.

  • Line 9: We create two variables of double types x and y, which respectively represent the numerator and denominator arguments.

  • Line 11: We use the remquo() function using x, y, and z as arguments. We also assign the output to another variable result.

  • Line 12: We print the result variable.

  • Line 13: We print the quotient z.

The logic in line 11, 12, and 13 is replicated in line 15 down to the last code.

RELATED TAGS

function
c++

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring