C++ Math logb
The function calculates the logarithm of a specified number, utilizing FLT_RADX as the base for the logarithm.
Typically, FLT_RADX equals 2. As a result, the function logb is the same as log2.
Syntax
Suppose a number is 'x'. Syntax would be:
float logb(float x);
double logb(double x);
long double logb(long double x);
double logb(integral x);
Parameter
x : The value for which the logarithm needs to be determined.
Return value
It returns base FLT_RADX logarithm of x.
If x equals zero, it could potentially lead to a domain or singularity error based on how the library is implemented.
Example 1
Let's consider a straightforward scenario where the variable x is of type integer.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x=6;
std::cout << "Value of x is :" <<x<< std::endl;
cout<<"logarithm value of x is:"<<logb(x);
return 0;
}
Output:
Value of x is :6
logarithm value of x is:2
In this instance, x is set to 6. The logb method calculates the logarithm of x with a base of FLT_RADX.
Example 2
Let's examine a basic scenario where the variable x is of the float data type.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=10.4;
std::cout << "Value of x is :" <<x<< std::endl;
cout<<"logarithm value of x is:"<<logb(x);
return 0;
}
Output:
Value of x is :10.4
logarithm value of x is:3
In this instance, the value assigned to x is 10.4. The logb method calculates the logarithm of x with a base of FLT_RADX.
Example 3
Let's examine a straightforward scenario where the value of x equals zero.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x=0;
std::cout << "Value of x is :" <<x<< std::endl;
cout<<"logarithm value of x is : "<<logb(x);
return 0;
}
Output:
Value of x is :0
logarithm value of x is : -inf