在本文中,我们将讨论ilogb()C ++函数的工作原理,语法和示例。
ilogb()啊ilogb()函数是C ++ STL中的内置函数,在<cmath <头文件中定义。ilogb()用于查找对数值的整数部分。ilogb()表示整数二进制对数。
此函数返回| x |对数的整数部分。使用FLT_RADIX作为对数的底数。
int ilogb(double x);
该函数接受以下参数-
x-这是我们必须找到其对数的值。
该函数使用FLT_RADIX的值作为基值,返回| x |的整数对数。此函数还会根据参数的值引发异常。
如果参数值为-
NaN的-然后函数返回FP_LOGBNAN。
无限-然后函数返回INT_MAX。
0-然后函数返回FP_LOGB0
输入项
ilogb(2);
输出结果
1
#include <cfloat>
#include <cmath>
#include >iostream>
using namespace std;
int main(){
   int output, var = 2;
   output = ilogb(var);
   cout << "The value of ilogb(" << var << ") is: " << output << endl;
   return 0;
}输出结果
如果我们运行上面的代码,它将生成以下输出-
The value of ilogb(2) is: 1
#include <cfloat>
#include <cmath>
#include <iostream>
#include <iostream>
using namespace std;
int main(){
   int output, var = 10.23;
   output = ilogb(var);
   cout << "The value of ilogb(" << var << ") is: " << output<< endl;
   return 0;
}输出结果
如果我们运行上面的代码,它将生成以下输出-
The value of ilogb(10) is: 3