The logb()
function in C++ is used to return the logarithm of a given number (|x|
) using the FLT_RADIX
as the base of the logarithm.
Note:
FLT_RADIX
is the value of the base of the logarithm. Generally, it is 2, so thelogb()
is equivalent tolog2()
for any positive number value.
The logb()
function is defined in the <cmath>
header file.
double logb (double x);
float logb (float x);
long double logb (long double x);
double logb (T x); // For integral type
The logb()
function takes a single parameter value:
x
: The number whose logarithm is computed.
The logb()
function returns the logarithm of the argument passed to it as its parameter value.
#include <iostream>#include <cmath>using namespace std;int main (){double x =100, result;result = logb(x);cout << "logb(" << x << ") = " << "log(|" << x << "|) = "<< result << endl;return 0;}
x
and result
.logb()
function on the x
variable and assign the output to the other variable result
.result
variable.