单精度和长双精度浮点余数 fmodf() fmodl()

Version >= C99

这些函数返回 x/y 除法的浮点余数。返回的值与 x 具有相同的符号。

单精度:

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

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

    float modulus = fmodf(x, y);

    printf("%f\n", modulus); /* lf would do as well as modulus gets promoted to double. */
}

输出:

4.90000

双倍精度:

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

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

    long double modulus = fmodl(x, y);

    printf("%Lf\n", modulus); /* Lf is for long double. */
}

输出:

4.90000