VS corrected me

I was watching this video and misunderstood something. I was mistakenly under the impression that Mathf.Log(32) was understood to be base 10 and not natural log.

So as I’m practicing in visual studio, I saw my error… Such a smart little program to correct its users!

2 Likes

In common math parlance, Log is generally base_10 and Ln in base_e.

In programming syntax, Log(x) is usually base_e and Log(x, b) is in the user specified base.

In the case of C#, you have a few options for calculating logs:
Math.Log(d) = base_e
Math.Log10(d) = base_10
Math.Log2(d) = base_2
Math.Log(d, d) = user specified base

In Unity specifically, The Mathf library drops the binary log option but keep the other three:
Mathf.Log(f) = base_e
Mathf.Log10(f)= base_10
Mathf.Log(f, f) = user specified base

3 Likes

ty ty ty!!! I really appreciate that. I am saving this post in a text file to refer back to…

Jenn

1 Like

You’d probably be better off bookmarking the documentation pages directly, as they contain all of this information and more!

Unity (UnityEngine.Mathf): https://docs.unity3d.com/ScriptReference/Mathf.html
Microsoft (System.Math): https://docs.microsoft.com/en-us/dotnet/api/system.math?view=net-5.0

2 Likes

I can do that! Thanks…

1 Like

Privacy & Terms