Share via


ldexp, ldexpf, ldexpl

將浮點數與 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 higher

float ldexp(
   float x,
   int exp
);  // C++ only
long double ldexp(
   long double x,
   int exp
);  // C++ only

參數

x
浮點值。

exp
整數指數。

傳回值

如果成功,函式會 ldexp 傳回 * 2 exp 的值 x 。 在溢位時,並根據 的 xldexp 正負號傳回 +/- HUGE_VAL ; errno 值會設定為 ERANGE

如需和可能錯誤傳回值的詳細資訊 errno ,請參閱 errno_doserrno_sys_errlist_sys_nerr

備註

因為 C++ 允許多載,所以您可以呼叫採用 ldexpfloat 類型的 long double 的多載。 在 C 程式中,除非您使用 < tgmath.h > 宏來呼叫此函式, ldexp 否則一律會採用 double 和 , int 並傳 double 回 。

如果您使用 < tgmath.h >ldexp() 宏,引數的類型會決定選取哪一個函式版本。 如需詳細資訊,請參閱 類型泛型數學

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

常式 C 標頭 C++ 標頭
ldexp, ldexpf, ldexpl <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

另請參閱

數學和浮點支援
frexp
modf, modff, modfl