约 1307 字

约 7 分钟

#C 语言标准库函数 compoundnl

#include <math.h>

long double compoundnl(long double x, long long int n);

说明

计算 1 加上输入后再取整数次幂,适用于复利或乘法增长因子。

x 小于 -1 时发生定义域错误。x 等于 -1 且 n 为负时可能发生极点错误。

自 C23 起提供。

参数

  • x - 每期的相对变化量。
  • n - 整数期数。

返回值

  • 返回 (1 + x) 的 n 次幂。

#示例

使用 GCC 时,在链接命令末尾添加 -lm。

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

int main(void)
{
    long double computed = compoundnl(0.5L, 2);
    printf("%Lg\n", (long double)computed);
    return !(computed == 2.25);
}

运行结果。

2.25

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28