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

FLT_ROUNDS宏


概要:

#define FLT_ROUNDS value //value值由实现定义。


描述:

该宏表示舍入模式。浮点加法的舍入模式由宏FLT_ROUNDS的实现定义值决定。

FLT_ROUNDS的可能值:

-1   舍入模式不明确。
0   向0舍入。
1   就近舍入。
2   向+∞舍入。
3   向-∞舍入。

如果宏FLT_ROUNDS存在其它值,将由实现定义舍入模式。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
/*宏FLT_ROUNDS范例*/

#include <fenv.h>
#include <float.h>
#include <stdio.h>

#pragma STDC FENV_ACCESS ON

int main(void)
{
    puts("Default rounding direction of floating-point operations:");
    printf("FLT_ROUNDS = %d\n",FLT_ROUNDS);

    fesetround(FE_UPWARD);
    puts("Current rounding direction of floating-point operations:");
    printf("FLT_ROUNDS = %d\n",FLT_ROUNDS);

    return 0;
}


输出:

Default rounding direction of floating-point operations:

FLT_ROUNDS = 1

Current rounding direction of floating-point operations:

FLT_ROUNDS = 2

:使用fesetround函数修改舍入模式时,宏FLT_ROUNDS值应该能够反映这种变化;但各编译器支持程度不一样,Visual Studio 2017Pelles C能够反映这种变化。


相关内容:
FLT_EVAL_METHOD 表示评估方法的宏。