log10() Function in C++ Last Updated : 22 Oct, 2024 Suggest changes Share Like Article Like Report 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 of log10() #include <iostream> #include <cmath> using namespace std; int main() { cout << log10(100.00) << endl; cout << log10(1); return 0; } Output2 0log10() Syntaxstd::log10(n);Parametersn: Value whose base 10 logarithm is to be calculated. Can be of any numeric type such as int, long, float, double, etc.Return ValueThe log10() function returns different values depending on the parameter:Returns base 10 logarithm of given number, if number is greater than 1.Return negative integer, if number is in between 0 and 1 (not inclusive).Returns -inf (infinity) , if the number is 0.Returns inf (infinity) , if the number is very large.Returns NaN (Not a Number), if the number is negative.More Examples of log10()The following examples demonstrate the behaviors of std::log10() function in different scenarios.Example 1: Calculating log10() for Different Number Types C++ // C++ Program to compute log10() for different // number types #include <bits/stdc++.h> using namespace std; int main() { // Calculating log10() for different // types of numeric values cout << log10(100) << endl; cout << log10(1000.5f) << endl; cout << log10(10000.123); return 0; } Output2 3.00022 4.00001Example 2: Using log10() for Negative Numbers and Zero C++ // C++ Program to check the output of log10() // with negative numbers #include <iostream> #include <cmath> using namespace std; int main() { // log10 of a negative number cout << log10(-100.0) << endl; // log10 of a negative number cout << log10(0); return 0; } Outputnan -inf Advertise with us Next Article log10() Function in C++ A anmolpanxq Follow Similar Reads 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 logb() function in C++ STL 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 parame 2 min read valarray log10() function in C++ The log10() function is defined in valarray header file. This function is used to calculate common logarithm of the value of the elements in valarray. Syntax: log10(varr); Parameter: This function takes a mandatory parameter varr which represents valarray. Returns: This function returns a valarray c 2 min read Functions in C++ A function is a building block of C++ programs that contains a set of statements which are executed when the functions is called. It can take some input data, performs the given task, and return some result. A function can be called from anywhere in the program and any number of times increasing the 9 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 Article Tags : C++ CPP-Library CPP-Functions cpp-math Practice Tags : CPP Like