C++ Math scalbn()
C++ Math scalbn()
该函数计算给定数字与FLT_RADX乘幂的乘积。
假设数字为" x",指数为" n":
scalbn(x,n) = x * ( FLT_RADX)n
语法
float scalbn(float x, int n);
double scalbn(double x, int n);
long double scalbn(long double x, int n);
double scalbn(integral x, int n);
参数
x : 有效数字的值。
n : 有效值
返回值
它将x和FLT_RADX的乘积返回到幂n。
示例1
让我们看一下x的值为整数类型的简单示例。
#include <iostream>
#include<math.h>
#include<float.h>
using namespace std;
int main()
{
int x=4;
int n=2;
std::cout << "Value of x is : " <<x<< std::endl;
cout<<"4 * 2^2 = "<<scalbn(x,n);
return 0;
}
输出:
Value of x is : 4
4 * 2^2 = 16
在此示例中,x的值为4、因此,scalbn()函数通过将FLT_RADX升至幂2来缩放4、
示例2
让我们看一下x的值为浮点型的简单示例。
#include <iostream>
#include<math.h>
#include<float.h>
using namespace std;
int main()
{
float x=3.4;
int n=5;
std::cout << "Value of x is : " <<x<< std::endl;
cout<<"3.4 * 2^5 = "<<scalbn(x,n);
return 0;
}
输出:
Value of x is : 3.4
3.4 * 2^5 = 108.8
在此示例中,x的值为3.4、因此,scalbn()函数通过将FLT_RADX升至5的幂来缩放3.4、