將浮點數與 2 的整數冪相乘。
語法
double ldexp(
double x,
int exp
);
float ldexpf(
float x,
int exp
);
long double ldexpl(
long double x,
int exp
);
#define ldexp(X, INT) // Requires C11 or later
float ldexp(
float x,
int exp
); // C++ only
long double ldexp(
long double x,
int exp
); // C++ only
參數
x
浮點值。
exp
整數指數。
傳回值
如果成功,函式會ldexp傳回 * 2exp 的值x。 在溢位時,並根據的xldexp正負號傳回 +/- HUGE_VAL;errno值會設定為 ERANGE。
如需和可能錯誤傳回值的詳細資訊errno,請參閱errno、 _doserrno_sys_errlist和 _sys_nerr。
備註
因為 C++ 允許多載,所以您可以呼叫採用 ldexp 和 float 類型的 long double 的多載。 在 C 程式中,除非您使用 <tgmath.h> 巨集來呼叫此函式, ldexp 否則一律會採用 double 和 , int 並傳 double回 。
如果您使用 <tgmath.h>ldexp() 巨集,則引數的型別會決定選取哪一個函式版本。 如需詳細資料,請參閱型別泛型數學。
根據預設,此函式的全域狀態會限定於應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。
需求
| 常式 | C 標頭 | C++ 標頭 |
|---|---|---|
ldexp、 、 ldexpfldexpl |
<math.h> | <cmath> |
ldexp 巨集 |
<tgmath.h> |
如需相容性資訊,請參閱相容性。
範例
// crt_ldexp.c
#include <math.h>
#include <stdio.h>
int main( void )
{
double x = 4.0, y;
int p = 3;
y = ldexp( x, p );
printf( "%2.1f times two to the power of %d is %2.1f\n", x, p, y );
}
輸出
4.0 times two to the power of 3 is 32.0