C++ STL 中的 ilogb() 函数
在本文中,我们将讨论 C++ 中 ilogb() 函数的工作原理、语法和示例。
什么是 ilogb()?
ilogb() 函数是 C++ STL 中的一个内置函数,定义在 <cmath< 头文件中。ilogb() 用于查找对数值的整数部分。ilogb() 表示整数二进制对数。
此函数使用 FLT_RADIX 作为对数的底数,返回 |x| 对数的整数部分。
语法
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP