logb() function in C++ STL Last Updated : 14 Feb, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The logb() is a builtin function in C++ STL which returns the logarithm of |x|, using FLT_RADIX as base for the logarithm. In general, the value of FLT_RADIX is 2, so logb() is equivalent to log2()(for positive values only). Syntax: logb(val) Parameter: The function accepts a single mandatory parameter val which specifies the val whose logb() is to be calculated. The data-type can be of double, float, long double or int. Return Type: The function returns the logarithm of |x|. Below programs illustrate the above function. Time Complexity: O(1) Space complexity: O(1) Program 1: CPP // C++ program to illustrate // to implement logb() function // when data-type is integer #include <cmath> #include <iostream> using namespace std; int main() { double result; int x = -10; result = logb(x); cout << "logb(" << x << ") = " << "log(|" << x << "|) = " << result << endl; x = 10; result = logb(x); cout << "logb(" << x << ") = " << "log(|" << x << "|) = " << result << endl; return 0; } Output:logb(-10) = log(|-10|) = 3 logb(10) = log(|10|) = 3 Program2: CPP // C++ program to illustrate // to implement logb() function // when data-type is double #include <cmath> #include <iostream> using namespace std; int main() { double x = 70.56, result; result = logb(x); cout << "logb(" << x << ") = " << "log(|" << x << "|) = " << result << endl; x = 17.6; result = logb(x); cout << "logb(" << x << ") = " << "log(|" << x << "|) = " << result << endl; return 0; } Output:logb(70.56) = log(|70.56|) = 6 logb(17.6) = log(|17.6|) = 4 Program3: CPP // C++ program to illustrate // to implement logb() function // when input is 0 #include <cmath> #include <iostream> using namespace std; int main() { double result; int x = 0; result = logb(x); cout << "logb(" << x << ") = " << "log(|" << x << "|) = " << result << endl; return 0; } Output:logb(0) = log(|0|) = -inf Comment More infoAdvertise with us Next Article strol() function in C++ I IshwarGupta Follow Improve Article Tags : Misc C++ STL CPP-Functions cpp-math +1 More Practice Tags : CPPMiscSTL Similar Reads ilogb() function in C++ STL The ilogb(x) function in C++ STL returns the integral part of the logarithm of |x|, by using the FLT_RADIX as base for the logarithm. In general, the value of FLT_RADIX is 2, so ilogb() is equivalent to ilog2()(for positive values only). Syntax: ilogb(x) Parameter: The function accepts a single mand 2 min read log() Function in C++ The std::log() in C++ is a built-in function that is used to calculate the natural logarithm (base e) of a given number. The number can be of any data type i.e. int, double, float, long long. It is defined inside the <cmath> header file.In this article we will learn about how to use std::log() 1 min read scalbln() function in C++ STL The scalbln() is a built-in function in C++ STL which takes two arguments and scales x by FLT_RADIX raised to the power n. The function returns the product of x and FLT_RADIX raised to the power n. FLT_RADIX: It is the value of the radix (integer base) of the exponent representation. Syntax: scalbln 2 min read log10() Function in C++ The std::log10() in C++ is a built-in function that is used to calculate the base-10 logarithm of a given number. It is defined inside <cmath> header file. In this article, we will learn about log10() in C++ and its behavior for different values.Example:C++// C++ Program to illustrate the use 2 min read strol() function in C++ The strtol() function in C++ interprets the contents of a string as an integral number of the specified base and return its value as a long int.This function also sets an end pointer that points to the first character after the last valid numeric character of the string, if there is no such characte 3 min read strtol() function in C++ STL The strtol() function is a builtin function in C++ STL which converts the contents of a string as an integral number of the specified base and return its value as a long int. Syntax: strtol(s, &end, b) Parameters: The function accepts three mandatory parameters which are described as below: s: s 4 min read Like