fe_dec_getround函数
概要:
#include <fenv.h>
#ifdef __STDC_IEC_60559_DFP__
int fe_dec_getround(void);
#endif
描述:
该函数获取十进制浮点操作动态舍入模式的当前值。
参数:
无。
返回值:
函数返回表示十进制浮点操作当前动态舍入方向的舍入模式宏值;如果不存在十进制浮点操作舍入模式宏或者当前舍入模式不确定,函数返回负值。
范例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/*函数fe_dec_getround范例*/
#include <fenv.h>
#include <stdio.h>
#pragma STDC FENV_ACCESS ON
#ifndef __STDC_IEC_60559_DFP__
#error "The implementation does not support decimal floating-point type operations."
#endif
void showDecimalRound(void)
{
switch(fe_dec_getround())
{
case FE_DEC_DOWNWARD:
puts("FE_DEC_DOWNWARD");
break;
case FE_DEC_TONEAREST:
puts("FE_DEC_TONEAREST");
break;
case FE_DEC_TONEARESTFROMZERO:
puts("FE_DEC_TONEARESTFROMZERO");
break;
case FE_DEC_TOWARDZERO:
puts("FE_DEC_TOWARDZERO");
break;
case FE_DEC_UPWARD:
puts("FE_DEC_UPWARD");
break;
default:
puts("Unknown dynamic rounding direction mode for decimal floating-point operations.");
break;
}
}
int main(void)
{
puts("Default rounding direction for decimal floating-point operations:");
showDecimalRound();
fe_dec_setround(FE_DEC_DOWNWARD);
puts("Current rounding direction for decimal floating-point operations:");
showDecimalRound();
return 0;
}
|
可能输出:
Default rounding direction for decimal floating-point operations:
FE_DEC_TONEAREST
Current rounding direction for decimal floating-point operations:
FE_DEC_DOWNWARD
(注:编译时实现还未支持fe_dec_getround函数和fe_dec_setround函数。)
相关内容:
主要参考资料:
1、ISO/IEC 9899:2024
2、IEEE 754:2019