remainder(), remainderf(), remainderl() — Computes the remainder x REM y
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
Format
#define _XOPEN_SOURCE_EXTENDED 1
#include <math.h>
double remainder(double x, double y);
C99
#define _ISOC99_SOURCE
#include <math.h>
float remainderf(float x, float y);
long double remainderl(long double x, long double y);
C++
TR1 C99
#define _TR1_C99
#include <math.h>
float remainder(float x, float y);
long double remainder(long double x, long double y);
General description
The remainder()
function returns the floating-point remainder when y is
nonzero and following the relation
The
value n is the integral value nearest the
exact value x/y and
when
then the value of n is even.
Note: The
following table shows the viable formats for these functions. See IEEE binary floating-point for more information about IEEE
Binary Floating-Point.
Function | Hex | IEEE |
---|---|---|
remainder | X | X |
remainderf | X | X |
remainderl | X | X |
Restriction: The
remainderf() function does not support the _FP_MODE_VARIABLE feature
test macro.
Returned value
If successful, remainder() returns the remainder of the division of x by y as described.
If y is zero, remainder() returns HUGE_VAL and sets errno to EDOM.
If r = 0, then its sign will be that of x.
Special behavior for IEEE: If successful, remainder() returns the remainder of the division of x by y.
If y is zero, remainder() returns NaNQ and sets errno to EDOM..
Example
/*
* This program illustrates the use of remainder() function
*
*/
#define _ISOC99_SOURCE
#include <math.h>
#include <stdio.h>
void main() {
double number1=3.0, number2=3.5;
printf("Illustrates the remainder() function");
#ifdef __BFP__
printf(" (IEEE version)\n\n");
#else
printf(" (HFP version)\n\n");
#endif
printf("remainder(%.2f,%.2f)=%.2f\n",number1,number2,
remainder(number1,number2));
number1=1; number2=2;
printf("remainder(%.2f,%.2f)=%.2f\n",number1,number2,
remainder(number1,number2));
number1=1; number2=0;
printf("remainder(%.2f,%.2f)=%.2f\n",number1,number2,
remainder(number1,number2));
}
Output
Illustrates the remainder() function (IEEE version)
remainder(3.00,3.50)=-0.50
remainder(1.00,2.00)=1.00
remainder(1.00,0.00)=NaNQ(1)