ldexp
將浮點數與 2 的整數冪相乘。
double ldexp( double x, int exp ); float ldexp( float x, int exp ); // C++ only long double ldexp( long double x, int exp ); // C++ only float ldexpf( float x, int exp ); long double ldexpl( long double x, int exp );
參數
x
浮點值。exp
整數指數。
傳回值
若成功,ldexp 函數會傳回 x * 2exp 的值。 溢位且根據 x 的符號時,ldexp 會傳回 +/– HUGE_VAL;errno 值會設為 ERANGE。
如需有關 errno 和其他可能的錯誤傳回值的詳細資訊,請參閱 errno、_doserrno、_sys_errlist 和 _sys_nerr。
備註
因為 C++ 允許多載,所以您可以呼叫採用 float 和 long double 類型的 ldexp 的多載。 在 C 程式中,ldexp 會一律採用 double 和 int 並傳回 double。
需求
常式 |
C 標頭 |
C++ 標頭 |
---|---|---|
ldexp, ldexpf, ldexpl |
<math.h> |
<cmath> |
如需相容性資訊,請參閱 相容性。
範例
// 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