C语言单精度和长双精度浮点余数:fmodf(),fmodl()
示例
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
以上是 C语言单精度和长双精度浮点余数:fmodf(),fmodl() 的全部内容, 来源链接: utcz.com/z/337916.html