无涯教程-ilogb(x)函数

54 阅读1分钟

该函数返回给定数字的指数部分,即logx的整数部分。

ilogb()函数等效于(int)logb()

ilogb - 语法

int ilogb(float x);
int ilogb(double x);
int ilogb(long double x);
int ilogb(integral x);

ilogb - 参数

x :这是要计算其指数的值。

ilogb - 返回值

参数 返回值
x=0 -INT_MIN
x=NAN or +inf or _inf INT_MAX

ilogb - 例

让我们看一个简单的例子

#include <iostream>
#include<math.h>
#include<float.h>
using namespace std;
int main()
{
 int x=4;
 std::cout << "Value of x is : " <<x<< std::endl;
 cout<<"Exponent value of x is : "<<ilogb(x);
 return 0;
}

输出:

Value of x is : 4
Exponent value of x is : 2

参考链接

www.learnfk.com/c++/cpp-mat…