pow ()- 计算电源 ®
格式
#include <math.h>
double pow(double x, double y);语言级别
ANSI
线程安全
是
描述
pow() 函数将 x 的值计算为 y的幂。
返回值
如果 y 是 0,那么 pow() 函数将返回值 1。 如果 x 为 0 且 y 为负数,那么 pow() 函数会将 errno 设置为 EDOM 并返回 0。 如果 x 和 y 都是 0,或者如果 x 是负数且 y 不是整数,那么 pow() 函数会将 errno 设置为 EDOM,并返回 0。 errno 变量也可以设置为 ERANGE。 如果溢出结果,那么 pow() 函数将返回 + HUGE_VAL (对于大结果) 或 -HUGE_VAL (对于小结果)。
示例
此示例计算 23的值。
#include <math.h>
#include <stdio.h>
int main(void)
{
double x, y, z;
x = 2.0;
y = 3.0;
z = pow(x,y);
printf("%lf to the power of %lf is %lf\n", x, y, z);
}
/***************** Output should be similar to: *****************
2.000000 to the power of 3.000000 is 8.000000
*/