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) 分解为一个尾数 (m) 和一个指数 (n),这样,m 的绝对值将大于或等于 0.5 且小于 1.0,并且 x = m * 2n。 整数指数 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
modfmodffmodfl