当前位置: C语言 -- 标准库 -- <math.h> -- fmod

fmod函数


概要:
#include <math.h>
double fmod(double x, double y);

描述:

该函数计算表达式x/y的浮点余数。


参数:
double x

参数为一个double类型的浮点数。

double y

参数为一个double类型的浮点数。


返回值:

函数返回x - ny的值,其中nx/y0舍入得到的整数。如果参数y为非0值,结果与参数x具有相同的符号,并且绝对值小于参数y的绝对值。如果参数y0,是发生域错误,还是返回0,将由实现定义。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
/*函数fmod范例*/

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

int main(void)
{
    double x = -4.0;
    double y = 5.0;
    double z = 7.0;

    printf("fmod(%.2f,%.2f) = %.2f\n", y, x, fmod(y,x));
    printf("fmod(%.2f,%.2f) = %.2f\n", z, x, fmod(z,x));

    return 0;
}

输出:

fmod(5.00,-4.00) = 1.00

fmod(7.00,-4.00) = 3.00


相关内容:
fmodf float类型的计算余数函数。
fmodl long double类型的计算余数函数。