log() Function in C++ Last Updated : 08 Apr, 2025 Suggest changes Share Like Article Like Report 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() in C++.Example of std::log() C++ // C++ program to show the working of log() #include <bits/stdc++.h> using namespace std; int main() { // Return positive integer if the number is // greater than 1 cout << log(11) << endl; // Return negative integer if the number is // between 0 and 1 (not inclusive) cout << log(0.5) << endl; // Return 0 if the number is 1 cout << log(1) << endl; // Return -inf (infinity) if the number is 0 cout << log(0) << endl; // Return inf (infinity) if the number is very large cout << log(1e1000) << endl; // Return NaN (Not a Number) if the number is ngative cout << log(-11) << endl; return 0; } Output2.3979 -0.693147 0 -inf inf nan Syntaxstd::log(n);Parametersn: Value whose natural logarithm is to be found.Return ValueReturns the natural log (base e) of the value Advertise with us Next Article log() Function in C++ S Striver Follow Similar Reads 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 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 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 std::function in C++ The std::function() in C++ is a function wrapper class which can store and call any function or a callable object. In this article, we will learn about std::function in C++ and how to use it in different cases.Table of ContentWhat is std::function in C++?Example of std::functionMember Functions of s 5 min read Article Tags : Misc C++ STL CPP-Library Practice Tags : CPPMiscSTL Like