取得浮點數的尾數和指數。
語法
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 later
float frexp(
float x,
int * expptr
); // C++ only
long double frexp(
long double x,
int * expptr
); // C++ only
參數
x
浮點值。
expptr
預存整數指數的指標。
傳回值
frexp 會傳回尾數。 如果 x 是 0,則此函式會針對尾數和指數傳回 0。 如果 expptr 為NULL,則會叫用無效的參數處理程式,如參數驗證中所述。 若允許繼續執行,此函式會將 errno 設為 EINVAL,並傳回 0。
備註
函frexp式會將浮點值 (x) 分解成 mantissa (m) 和指數 (n),使 的m絕對值大於或等於 0.5 且小於 1.0,而 = m x* 2。n 整數指數 n 儲存在 expptr 所指向的位置。
C++ 允許多載,因此您可以呼叫 frexp 多載。 在 C 程式中,除非您使用 <tgmath.h> 巨集來呼叫此函式, frexp 否則一律會採用 double 和 int 指標並傳 double回 。
如果您使用 <tgmath.h>frexp() 巨集,則引數的型別會決定選取哪一個函式版本。 如需詳細資料,請參閱型別泛型數學。
根據預設,此函式的全域狀態會限定於應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。
需求
| 函式 | 必要的標頭 |
|---|---|
frexp、 、 frexpffrexpl |
<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