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

remainderd32函数


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

描述:

该函数计算ISO/IEC 60559标准要求的余数(x REM y)。

当参数y≠0时,余数r=x REM y由数学表达式r=x-ny定义,与舍入模式无关,其中n是最接近表达式x/y值的整数;当|n-x/y|=1/2时,n是偶数。如果r=0,r的符号应和参数x的符号相同。此定义适用于所有实现。

如果参数y为0,是发生域错误,还是返回0,将由实现定义。


参数:
_Decimal32 x

参数为_Decimal32类型的浮点数。

_Decimal32 y

参数为_Decimal32类型的浮点数。


返回值:

函数返回(x REM y)。


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

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

int main(void)
{
    #if __STDC_VERSION_MATH_H__ >= 202311L && defined(__STDC_IEC_60559_DFP__)
        _Decimal32 x = 5.0df;
        _Decimal32 y = 7.0df;
        _Decimal32 z = 4.0df;
        
        printf("remainderd32(%.2Hf,%.2Hf) = %.2Hf\n", x, z, remainderd32(x,z));
        printf("remainderd32(%.2Hf,%.2Hf) = %.2Hf\n", y, z, remainderd32(y,z));
    #else
        puts("The implementation does not support remainderd32 function.");
    #endif

    return 0;
}

可能输出:

remainderd32(5.00,4.00) = 1.00

remainderd32(7.00,4.00) = -1.00

(注:编译时实现还未支持remainderd32函数。)


相关内容:
remainder double类型的计算余数函数。
remainderf float类型的计算余数函数。
remainderl long double类型的计算余数函数。
remainderd64 _Decimal64类型的计算余数函数。
remainderd128 _Decimal128类型的计算余数函数。


主要参考资料:

1、ISO/IEC 9899:2024