#C 语言标准库函数 compoundnd64
#include <math.h>
_Decimal64 compoundnd64(_Decimal64 x, long long int n);
说明
计算 1 加上输入后再取整数次幂,适用于复利或乘法增长因子。
x 小于 -1 时发生定义域错误。x 等于 -1 且 n 为负时可能发生极点错误。
自 C23 起提供。需要实现定义 __STDC_IEC_60559_DFP__ 并提供对应的十进制浮点接口。
参数
x- 每期的相对变化量。n- 整数期数。
返回值
- 返回 (1 + x) 的 n 次幂。
#示例
使用 GCC 时,在链接命令末尾添加 -lm。
#include <math.h>
#include <stdio.h>
int main(void)
{
_Decimal64 computed = compoundnd64(0.5dd, 2);
printf("%Lg\n", (long double)computed);
return !(computed == 2.25dd);
}
运行结果。
2.25
#相关接口
- 接口变体 compoundn、compoundnf、compoundnl、compoundnd32、compoundnd128
- 类型通用分派 compoundn(类型通用宏)
- 相关操作 powd64、pownd64、rootnd64