该函数frexp()用于将浮点数分解为2的二进制有效位数和整数指数。它返回二进制有效位数,其范围为(0.5,1)。如果我们传递零值,则其有效和指数值将为零。
这是的数学表达式frexp(),
x = significand * (2^exponent)
这是frexp()C ++语言的语法,
float frexp(float variable_name, int* exponent);
这里,
variable_name-具有浮点数的任何变量 名称都将分解为二进制有效。
exponent- 它是一个指向int的指针,在其中存储了exponent的值。
这是frexp()C ++语言的示例,
#include <iostream>
#include<math.h>
using namespace std;
int main() {
double a = 4;
int* b;
cout<<"Value of a : "<< a <<'\n';
double s = frexp(a, b);
std::cout << a << " = " << s << " * " << "2^" << *b;
return 0;
}输出结果
这是输出:
Value of a : 4 4 = 0.5 * 2^3