frexp, frexpf, frexpl

取得浮點數的尾數和指數。

語法

double frexp(
   double x,
   int *expptr
);
float frexpf(
   float x,
   int * expptr
);
long double frexpl(
   long double x,
   int * expptr
);
#define frexpl(X, INT_PTR) // Requires C11 or higher
float frexp(
   float x,
   int * expptr
);  // C++ only
long double frexp(
   long double x,
   int * expptr
);  // C++ only

參數

x
浮點值。

expptr
預存整數指數的指標。

傳回值

frexp 會傳回尾數。 如果 x 是 0,則此函式會針對尾數和指數傳回 0。 如果 expptrNULL ,則會叫用不正確參數處理常式,如參數驗證 中所述 。 若允許繼續執行,此函式會將 errno 設為 EINVAL,並傳回 0。

備註

frexp 式會將浮點值 ( x ) 分解成 mantissa ( m ) 和指數 ( n ),使 的 m 絕對值大於或等於 0.5 且小於 1.0,而 mx = * 2。 n 整數指數 n 儲存在 expptr 所指向的位置。

C++ 允許多載,因此您可以呼叫 frexp 多載。 在 C 程式中,除非您使用 < tgmath.h > 宏來呼叫此函式, frexp 否則一律會採用 doubleint 指標並傳 double 回 。

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

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

需求

函式 必要的標頭
frexp, frexpf, frexpl <math.h>
frexp 宏觀 <tgmath.h>

如需相容性詳細資訊,請參閱相容性

範例

// crt_frexp.c
// This program calculates frexp( 16.4, &n )
// then displays y and n.

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

int main( void )
{
   double x, y;
   int n;

   x = 16.4;
   y = frexp( x, &n );
   printf( "frexp( %f, &n ) = %f, n = %d\n", x, y, n );
}
frexp( 16.400000, &n ) = 0.512500, n = 5

另請參閱

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