pow、powf、powl

计算x提升到y。

double pow(
   double x,
   double y 
);
double pow(
   double x,
   int y
);  // C++ only
float pow(
   float x,
   float y 
);  // C++ only
float pow(
   float x,
   int y
);  // C++ only
long double pow(
   long double x,
   long double y
);  // C++ only
long double pow(
   long double x,
   int y
);  // C++ only
float powf(
   float x,
   float y 
);
long double powl(
   long double x,
   long double y
);

参数

  • x
    基数。

  • y
    指数。

返回值

返回 xy的值。 错误消息在溢出或下溢时不打印。

x 和 y 的值

返回pow的值

x<>0 和y = 0.0

1

x = 0.0 和 y = 0.0

1

x = 0.0 和 y< 0

INF

备注

pow 无法识别大于 264的集成浮点值 (例如,1.0E100)。

pow 具有使用Streaming SIMD Extensions 2(SSE2)的实现。 有关使用SSE2实现的信息和限制,请参见 _set_SSE2_enable

由于 C++ 允许重载,可以调用pow的任意重载函数。 在 C 程序中,pow 始终采用两个双精度值并返回一个双精度值。

pow(int, int)重载不再可用。 如果使用此重载,编译器会发出 C2668。 若要避免此问题,请将第一个参数转换为double、float或 long double。

要求

例程

必需的标头

pow, powf, powl

<math.h>

有关其他兼容性信息,请参见兼容性

C 运行时库的所有版本。

示例

// crt_pow.c

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

int main( void )
{
   double x = 2.0, y = 3.0, z;

   z = pow( x, y );
   printf( "%.1f to the power of %.1f is %.1f\n", x, y, z );
}

Output

2.0 to the power of 3.0 is 8.0

.NET Framework 等效项

System::Math::Pow

请参见

参考

浮点支持

exp、expf

log、logf、log10、log10f

sqrt、sqrtf、sqrtl

_CIpow