English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++The logb() function in uses FLT_RADIX as the base of the logarithm and returns the logarithm of |x|.
Generally, FLT_RADIX is2,so for positive values, logb() is equivalent tolog2().
The function is in<cmath>header file is defined.
double logb(double x); float logb(float x); long double logb(long double x); double logb(T x); //For integer types
The logb() function has only one parameter and returns a value of type double, float, or long double.
The ilogb() function takes one parameter, whose logb is calculated.
The logb() function uses FLT_RADIX as the base of the logarithm and returns the logarithm of |x|.
If x is zero, it may cause domain error, pole error, or no error, depending on the library implementation.
#include <iostream> #include <cmath> using namespace std; int main () { double x = 121.056, result; result = logb(x); cout << "logb(" << x << ") = " << "log(|" << x << "|) = "<< result << endl; return 0; }
When running the program, the output is:
logb(121.056) = log(|121.056|) = 6
#include <iostream> #include <cmath> using namespace std; int main () { double result; int x = -5; result = logb (x); cout << "logb(" << x << ") = " << "log(|" << x << "|) = "<< result << endl; return 0; }
When running the program, the output is:
logb(-5) = log(|-5|) = 2