当前位置: C语言 -- 标准库 -- <math.h> -- frexpf

frexpf函数


概要:
#include <math.h>
float frexpf(float value,int *p);

描述:

该函数将浮点数分解为规格化小数(normalized fraction)和整数幂,并将整数幂存入参数p指向的对象中。

参数value可使用以下形式表示:

value=x×2(*p)

如果函数返回类型是标准浮点类型(例如:float、double、long double。),指数是2的整数幂。


参数:
float value

参数为float类型的浮点数。

int *p

参数为指向int类型对象的指针,整数幂值将存入指针指向的对象中。


返回值:

如果参数value不是浮点数,或者如果整数幂超出int类型所能表示的范围,结果是未指定的;否则函数返回x,如果函数返回类型是标准浮点类型,x的绝对值在[1/2,1)区间内或者等于0,并且value=x×2(*p)。如果参数value值等于0,x和*p均为0。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
/*函数frexpf范例*/

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

int main(void)
{
    float value = 5.0f;
    int exponent;

    printf("The normalized fraction is %.6f.\n", frexpf(value,&exponent));
    printf("The integral power is %d.\n", exponent);

    return 0;
}

输出:

The normalized fraction is 0.625000.

The integral power is 3.


相关内容:
frexp 将double类型浮点数分解为规格化小数和整数幂的函数。
frexpl 将long double类型浮点数分解为规格化小数和整数幂的函数。
frexpd32 将_Decimal32类型浮点数分解为规格化小数和整数幂的函数。
frexpd64 将_Decimal64类型浮点数分解为规格化小数和整数幂的函数。
frexpd128 将_Decimal128类型浮点数分解为规格化小数和整数幂的函数。


主要参考资料:

1、ISO/IEC 9899:2024

2、ISO/IEC 9899:2018