frexp()函数将浮点数x分解为其二进制有效位数i,即绝对值介于[0.5,1.0)和2的整数指数之间的浮点。
x =有效数*(2 ^指数)。
它曾经:
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.
Return:
- 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.
Parameter:
错误和异常:
- 必须提供两个参数,否则将导致错误没有匹配函数调用’frexp()’ 。
- 如果我们将字符串作为参数传递,则将出现错误,没有匹配函数可调用’frexp(const char [n])。
-
- 如果x = 0,则有效数为零,指数为零
- x> = 1,则有效位数为正数,指数为正数
- x <= -1则有效位数为负数而指数为正数
- -1
- 0
- 0
#代码1
// CPP implementation of
// above function
#include
#include
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
#include
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
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。