frexp
获取一个浮点数的尾数和指数。
double frexp(
double x,
int *expptr
);
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 函数将浮点分解浮点值 (m) 为尾数 (x)和指数 (n),此绝对值 m 大于或等于 0.5 并且小于 1.0 和 x = m*2。n 整数的指数 n 存储的位置指向 expptr。
C++ 允许重载,因此可以调用 frexp 重载函数。 在 C 程序中,frexp 始终采用一个双精度值和一个整型并返回一个双精度值。
要求
功能 |
必需的标头 |
---|---|
frexp |
<math.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 );
}
.NET Framework 等效项
不适用。若要调用标准 C 函数,请使用 PInvoke。有关更多信息,请参见平台调用示例。