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