Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#include <math.h>
double fmod(double x, double y);
float fmod(float x, float y); /* C++ only */
long double fmod(long double x, long double y); /* C++ only */
float fmodf(float x, float y);
long double fmodl(long double x, long double y);
If y is 0, or the result would overflow, then the function returns 0. Errno remains unchanged.
Special behavior for IEEE
If successful, the function returns the floating-point remainder of x/y.
If y is 0, the function sets errno to EDOM and returns NaNQ. No other errors will occur.
⁄* CELEBF25
This example computes z as the remainder of x⁄y; here x⁄y is -3 with a
remainder of -1.
*⁄
#include <math.h>
#include <stdio.h>
int main(void)
{
double x, y, z;
x = -10.0;
y = 3.0;
z = fmod(x,y); ⁄* z = -1.0 *⁄
printf("fmod( %f, %f) = %lf\n", x, y, z);
}
fmod( -10.000000, 3.000000) = -1.000000