計算自乘至 y 的乘冪的 x。
語法
double pow( double x, double y );
float powf( float x, float y );
long double powl( long double x, long double y );
define pow(X, Y) // Requires C11 or later
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
參數
x
底數。
y
指數。
傳回值
傳回 xy 的值。 溢位或反向溢位時不會列印錯誤訊息。
x和的值y |
傳回值 pow |
|---|---|
x != 0.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 程式中,除非您使用 <tgmath.h> 巨集來呼叫此函式, pow 否則一律會採用兩 double 個 double 值並傳回值。
如果您使用 中的pow<tgmath.h>巨集,自變數的類型會決定選取哪一個函式版本。 如需詳細資料,請參閱型別泛型數學。
pow(int, int) 已無法使用。 如果您使用這個多載,編譯程式可能會發出 C2668。 若要避免這個問題,請將第一個參數轉換為 double、float 或 long double。
最初,多載會將 pow(T, int) 呼叫取消捲 pow 動到一連串的內嵌乘法作業中。 雖然速度更快,但它也不太準確。 Visual Studio 2015 Update 1 已移除此實作。 如需詳細資訊,請參閱 Visual Studio 2015 Update 1中的一致性改進。
根據預設,此函式的全域狀態會限定於應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。
需求
| 常式 | 必要的標頭 (C) | 必要的標頭 (C++) |
|---|---|---|
pow、 、 powfpowl |
<math.h> |
<math.h> 或 <cmath> |
pow 巨集 |
<tgmath.h> |
如需相容性詳細資訊,請參閱相容性。
範例
// 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 );
}
2.0 to the power of 3.0 is 8.0
另請參閱
數學與浮點支援
exp、 、 expfexpl
log、 、 logf、 log10log10f
sqrt、 、 sqrtfsqrtl
_CIpow