I am new to coding, and am a bit confused by how C++ differentiates between log base (any number) and natural log (base e) if both are represented by the same log()
function. Can anyone shed some light on this for me?
Asked
Active
Viewed 887 times
-2

Remy Lebeau
- 555,201
- 31
- 458
- 770

user2879906
- 17
- 1
-
1Please don't post an entire question in the post title. The title should be terse. The body of the post should contains a clear question, not just pleasantries. – StoryTeller - Unslander Monica Nov 09 '17 at 05:57
-
2Are you sure of this? I was under the impression that `log` was base e, `log10` was base 10, and that there was a small family of other log functions. – user4581301 Nov 09 '17 at 06:05
-
1In C++, `log()` and `log10()` are distinct functions with different names. An expression like `log10(x)` is not specified as being a call to `log()` with a base of `10`. – Peter Nov 09 '17 at 06:12
1 Answers
2
The Google's Internet Search Engine top result for phrase ""c++ log", fully answers your question :
using tgmath.h
natural
- double log (double x);
binary
double log2 (double x);
float log2f (float x);
long double log2l (long double x);
base 10
- double log10 (double x);
To conclude, different bases have different function names.

martin
- 100
- 6
-
Please note that
already contains all the necessary overloads, see e.g. http://en.cppreference.com/w/cpp/numeric/math/log10 – Bob__ Nov 09 '17 at 07:35