C++ <cmath> - logb() Function
The C++ <cmath> logb() function returns the logarithm of |x| (mod of argument), using FLT_RADIX as base for the logarithm.
On most platforms, FLT_RADIX is 2, which makes this function equivalent to log2() function for positive values.
Syntax
double logb (double x); float logb (float x); long double logb (long double x); double logb (T x);
Parameters
x |
Specify the value to calculate logarithm. |
Return Value
Returns the base-FLT_RADIX logarithm of |x|.
Example:
In the example below, logb() function is used to calculate the base-FLT_RADIX logarithm of absolute value of given numbers.
#include <iostream> #include <cmath> using namespace std; int main (){ cout<<"logb(10) = "<<logb(10)<<"\n"; cout<<"logb(-10) = "<<logb(-10)<<"\n"; return 0; }
The output of the above code will be:
logb(10) = 3 logb(-10) = 3
❮ C++ <cmath> Library