Format
#include <math.h>
double fmod(double x, double y);
Language Level: ANSI
Threadsafe: Yes.
Description
The fmod() function calculates the floating-point remainder of x/y. The absolute value of the result is always less than the absolute value of y. The result will have the same sign as x.
Return Value
The fmod() function returns the floating-point remainder of x/y. If y is zero or if x/y causes an overflow, fmod() returns 0. The value of errno can be set to EDOM.
Example that uses fmod()
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( %lf, %lf) = %lf\n", x, y, z);
}
/******************* Output should be similar to: ***************
fmod( -10.000000, 3.000000) = -1.000000
*/
Related Information