frexp()函数将浮点数x分解为其二进制有效位数,即绝对值介于[0.5,1.0)和2的整数 index 之间的浮点。
x =有效数*(2 ^ index )。
它曾经用于:
1. It is used to find significand which is always between 0.5 and 1.0 2. It is used to find exponent which is power of 2.
用法:
double frexp (double x); float frexp (float x); long double frexp (long double x);
参数:
- The frexp() function takes a single argument.
返回:
- The frexp() function returns the binary significand whose absolute value lies in the interval [0.5, 1).
- If x is zero, both significand and exponent are zero.
错误和异常:
- 必须提供两个参数,否则将产生错误的不匹配函数,无法调用“ frexp()”。
- 如果我们将字符串作为参数传递,则将出现错误,没有匹配的函数调用'frexp(const char [n])。
-
- 如果x = 0,则有效数为零, index 为零
- x> = 1,则有效位数为正数, index 为正数
- X
- -1
- 0
#代码1
// CPP implementation of
// above function
#include <cmath>
#include <iostream>
using namespace std;
// Driver program
int main()
{
double x = 5.35, significand;
int exponent;
significand = frexp(x, &exponent);
cout << x << " = " << significand
<< " * 2^" << exponent << endl;
return 0;
}
输出:
5.35 = 0.66875 * 2^3
#代码2
// CPP implementation of the
// above function
#include <cmath>
#include <iostream>
using namespace std;
// Driver program
int main()
{
double significand;
int exponent, x = 5;
significand = frexp(x, &exponent);
cout << x << " = " << significand
<< " * 2^" << exponent << endl;
return 0;
}
输出:
5 = 0.625 * 2^3
相关用法
注:本文由纯净天空筛选整理自pawan_asipu大神的英文原创作品 frexp() in C++。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。