C++中的LDEXP()

函数的作用是:取两个参数a和b,并返回a和2的乘积乘以b的幂,即a*(2) B ).

null

语法:

double ldexp (double a, double b);float ldexp (float a, float b);long double ldexp (long double a, long double b);

错误和例外 与此功能关联:

  1. 必须同时给出两个参数,否则会出现错误 没有匹配的函数用于调用’ldexp()’ .
  2. 如果我们将字符串作为参数传递,我们将得到错误 没有用于调用’ldexp’的匹配函数(常量字符[n],常量字符[n]) .
  3. 如果我们通过 标准::数值限制::最大值() 作为两个参数,我们将得到inf(无穷大)作为输出。

例如:

Input  : ldexp(5.35, 4)Output : 85.6Input  : ldexp(25, 5)Output : 800

#代码1

C++

// C++ implementation of the
// above function
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
double a = 5.35;
int b = 4;
cout << ldexp (a, b);
return 0;
}


输出:

85.6

#代码2

C++

// CPP implementation of the
// above function
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
int a = 25, b = 5;
cout << ldexp (a, b);
return 0;
}


输出:

800

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享