#C 语言标准库函数 pown
#include <math.h>
double pown(double x, long long int n);
说明
按整数指数计算乘方,可直接表示负底数的奇数次幂。
底数为零且指数为负时可能发生极点错误。结果超出类型可表示的范围时可能报告范围错误。数学错误的报告方式由 math_errhandling 指示。
自 C23 起提供。
参数
x- 底数。n- 整数指数,可为负。
返回值
- 返回 x 的 n 次幂。
#示例
使用 GCC 时,在链接命令末尾添加 -lm。
#include <math.h>
#include <stdio.h>
int main(void)
{
double computed = pown(-2.0, 3);
printf("%Lg\n", (long double)computed);
return !(computed == -8.0);
}
运行结果。
-8