remquo() Function

The remquo() function in C computes the remainder of the division between two floating-point numbers while also retrieving part of the quotient used internally during the computation. It provides both the remainder result and a portion of the integral quotient, which is stored in an external integer variable. This function is especially useful when both the remainder and certain information about the quotient are needed.


Syntax of remquo()

</>
Copy
double remquo(double numer, double denom, int *quot);

Parameters

ParameterDescription
numerFloating-point dividend.
denomFloating-point divisor.
quotPointer to an integer where a portion of the quotient is stored.

Return Value

The function returns the remainder of dividing the provided floating-point dividend by the divisor. If the remainder is zero, its sign matches that of the dividend. In the event of a domain error (such as division by zero), the function may return zero and set an error state according to the system’s math error handling.


Examples for remquo()

Example 1: Basic Computation of Remainder and Quotient Portion

This example demonstrates how to use remquo() to calculate the remainder and obtain a portion of the quotient for two positive numbers.

Program

</>
Copy
#include <stdio.h>
#include <math.h>

int main() {
    int q;
    double result = remquo(10.5, 3.0, &q);
    printf("Remainder: %f, Quotient Portion: %d\n", result, q);
    return 0;
}

Explanation:

  1. The program computes the remainder of 10.5 divided by 3.0 using remquo().
  2. The internal quotient used in the calculation is partially stored in the variable q.
  3. The result is printed, displaying both the remainder and the retrieved quotient portion.

Program Output:

Remainder: -1.500000, Quotient Portion: 4

Example 2: Handling Negative Values with remquo()

This example illustrates the behavior of remquo() when dealing with negative floating-point numbers, showing how the function computes the remainder and adjusts the sign accordingly.

Program

</>
Copy
#include <stdio.h>
#include <math.h>

int main() {
    int q;
    double result = remquo(-15.75, 4.0, &q);
    printf("Remainder: %f, Quotient Portion: %d\n", result, q);
    return 0;
}

Explanation:

  1. The program computes the remainder when -15.75 is divided by 4.0 using remquo().
  2. The computed remainder carries the sign of the dividend, and a part of the quotient is stored in the variable q.
  3. The results are printed, indicating how negative values are handled.

Program Output:

Remainder: 0.250000, Quotient Portion: -4

Example 3: Zero Remainder Scenario with remquo()

This example demonstrates the case when the computed remainder is zero. Note that the quotient portion stored in the provided variable may be unspecified in such cases.

Program

</>
Copy
#include <stdio.h>
#include <math.h>

int main() {
    int q;
    double result = remquo(8.0, 4.0, &q);
    printf("Remainder: %f, Quotient Portion: %d\n", result, q);
    return 0;
}

Explanation:

  1. The program divides 8.0 by 4.0 using remquo(), which results in a remainder of zero.
  2. Since the remainder is zero, its sign will match that of the dividend (8.0), but the stored quotient portion in q may be unspecified.
  3. The output shows the computed remainder and the associated quotient value.

Program Output:

Remainder: 0.000000, Quotient Portion: 2