Namespaces
Variants
Views
Actions

remquo

From cppreference.com
< c‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
remquo
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)(C99)(C99)
Exponential functions
(C99)
(C99)
(C99)
(C99)
Power functions
(C99)
(C99)
Trigonometric and hyperbolic functions
(C99)
(C99)
(C99)
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Nearest integer floating point operations
(C99)(C99)(C99)
(C99)
(C99)(C99)(C99)
Floating point manipulation functions
(C99)(C99)
(C99)
(C99)
Classification
(C99)
(C99)
(C99)
Macro constants
 
Defined in header <math.h>
float       remquof( float x, float y, int *quo );
(since C99)
double      remquo( double x, double y, int *quo );
(since C99)
long double remquol( long double x, long double y, int *quo );
(since C99)

Computes the remainder of the floating point division operation x/y as the remainder() function does. Additionally, the sign and at least the three of the last bits of x/y will be stored in quo.

Contents

[edit] Parameters

x, y - floating point values
quo - pointer to an integer value to store some bits of x/y in

[edit] Return value

Remainder of dividing arguments.

[edit] Example

remqo <-- 5.1 - (5.1/3.0) * 3.0
          5.1 - (1.7)     * 3.0
          5.1 - (2.0)     * 3.0  (rounded to nearest integer)
          5.1 - 6.0
          -0.9
quo   <-- (int)2.0

#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>
#include <string.h>
 
#pragma STDC FENV_ACCESS ON
 
void show_fe_exceptions(void)
{
    printf("current exceptions raised: ");
    if(fetestexcept(FE_DIVBYZERO))     printf(" FE_DIVBYZERO");
    if(fetestexcept(FE_INEXACT))       printf(" FE_INEXACT");
    if(fetestexcept(FE_INVALID))       printf(" FE_INVALID");
    if(fetestexcept(FE_OVERFLOW))      printf(" FE_OVERFLOW");
    if(fetestexcept(FE_UNDERFLOW))     printf(" FE_UNDERFLOW");
    if(fetestexcept(FE_ALL_EXCEPT)==0) printf(" none");
    printf("\n");
}
 
int main(void)
{
    int quo=0;
 
    printf("                                quo\n");
    printf("                                ---\n");
    printf("remquo(+5.1,+3.0,&quo) = %+.1f", remquo(+5.1,+3.0,&quo));
    printf("    %+2d\n", quo);
    printf("remquo(-5.1,+3.0,&quo) = %+.1f", remquo(-5.1,+3.0,&quo));
    printf("    %+2d\n", quo);
    printf("remquo(+5.1,-3.0,&quo) = %+.1f", remquo(+5.1,-3.0,&quo));
    printf("    %+2d\n", quo);
    printf("remquo(-5.1,-3.0,&quo) = %+.1f", remquo(-5.1,-3.0,&quo));
    printf("    %+2d\n", quo);
    printf("\n");
 
    /* When remainder is zero, sign of remainder is sign of x. */
    printf("remquo(+9.0,+3.0,&quo) = %+.1f", remquo(+9.0,+3.0,&quo));
    printf("    %+2d\n", quo);
    printf("remquo(-9.0,+3.0,&quo) = %+.1f", remquo(-9.0,+3.0,&quo));
    printf("    %+2d\n", quo);
    printf("\n");
 
    /* "invalid" floating-point exception          */
    /* quo is unspecified; ignore quo in this case */
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("remquo(1.0,0.0,&quo)   = %f", remquo(1.0,0.0,&quo));   /* y == 0 */
    printf("    %+2d\n", quo);
    printf("%s\n",strerror(errno));   /* compare with remainder() */
    show_fe_exceptions();
 
    return 0;
}

Output:

quo
                                ---
remquo(+5.1,+3.0,&quo) = -0.9    +2
remquo(-5.1,+3.0,&quo) = +0.9    -2
remquo(+5.1,-3.0,&quo) = -0.9    -2
remquo(-5.1,-3.0,&quo) = +0.9    +2
 
remquo(+9.0,+3.0,&quo) = +0.0    +3
remquo(-9.0,+3.0,&quo) = -0.0    -3
remquo(1.0,0.0,&quo)   = -nan    -3
 
remquo(1.0,0.0,&quo)   = -nan    -3
Success
current exceptions raised:  FE_INVALID

[edit] See also

signed remainder of the division operation
(function) [edit]
remainder of the floating point division operation
(function) [edit]
the quotient and remainder of integer division
(function) [edit]