约 1387 字

约 7 分钟

#C 语言标准库函数 pownd128

#include <math.h>

_Decimal128 pownd128(_Decimal128 x, long long int n);

说明

按整数指数计算乘方,可直接表示负底数的奇数次幂。

底数为零且指数为负时可能发生极点错误。结果超出类型可表示的范围时可能报告范围错误。数学错误的报告方式由 math_errhandling 指示。

自 C23 起提供。需要实现定义 __STDC_IEC_60559_DFP__ 并提供对应的十进制浮点接口。

参数

  • x - 底数。
  • n - 整数指数,可为负。

返回值

  • 返回 x 的 n 次幂。

#示例

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

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

int main(void)
{
    _Decimal128 computed = pownd128(-2.0dl, 3);
    printf("%Lg\n", (long double)computed);
    return !(computed == -8.0dl);
}

运行结果。

-8

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28