單精度和長雙精度浮點餘數 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