该函数计算给定数字与FLT_RADX乘幂的乘积。
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的乘积。
让我们看一下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。
让我们看一下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。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)