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

truncd32函数


概要:
#include <math.h>
#ifdef __STDC_IEC_60559_DFP__
    _Decimal32 truncd32(_Decimal32 x);
#endif 

描述:

该函数截取参数x的整数部分,并将整数部分以浮点形式表示。


参数:
_Decimal32 x

参数为_Decimal32类型的浮点数。


返回值:

函数返回浮点形式表示的参数x的整数部分。


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

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

int main(void)
{
    #if __STDC_VERSION_MATH_H__ >= 202311L && defined(__STDC_IEC_60559_DFP__)
        printf("truncd32(2.3df) = %.2Hf\n", truncd32(2.3df));
        printf("truncd32(2.7df) = %.2Hf\n", truncd32(2.7df));
        printf("truncd32(2.5df) = %.2Hf\n", truncd32(2.5df));
        printf("truncd32(-2.5df) = %.2Hf\n", truncd32(-2.5df));
    #else
        puts("The implementation does not support truncd32 function.");
    #endif

    return 0;
}


可能输出:

truncd32(2.3df) = 2.00

truncd32(2.7df) = 2.00

truncd32(2.5df) = 2.00

truncd32(-2.5df) = -2.00

(注:编译时实现还未支持十进制浮点类型。)


相关内容:
trunc 截取double类型参数整数部分的函数。
truncl 截取long double类型参数整数部分的函数。
truncf 截取float类型参数整数部分的函数。
truncd64 截取_Decimal64类型参数整数部分的函数。
truncd128 截取_Decimal128类型参数整数部分的函数。


主要参考资料:

1、ISO/IEC 9899:2024