Double precision floating-point remainder fmod

suggest change

This function returns the floating-point remainder of the division of x/y. The returned value has the same sign as x.

#include <math.h> /* for fmod() */
#include <stdio.h> /* for printf() */

int main(void)
{
    double x = 10.0;
    double y = 5.1;

    double modulus = fmod(x, y);

    printf("%.5f\n", modulus);

    return 0;
}
4.90000

Important: Use this function with care, as it can return unexpected values due to the operation of floating point values.

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

int main(void)
{
    printf("%.1f\n", fmod(1, 0.1));
    printf("%19.17f\n", fmod(1, 0.1));
    return 0;
}
0.1
0.09999999999999995

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents