Home
Map
Math.Log and Log10 MethodsUse the Math.Log and Math.Log10 methods from the System namespace.
C#
This page was last reviewed on Oct 11, 2022.
Math.Log, Log10. The Math class provides logarithms. With the Math.Log and Math.Log10 methods in the System namespace, we compute logarithms with a specific base or base 10.
These methods are tested—they do not need to be debugged. If you need to optimize their performance, try using a lookup table to cache or precompute the most common values.
Memoization
Math.Round
Math
An example. Here we compute the logarithms of some known numbers. The logarithm of 1 with base "e" is always zero—the method matches this result.
And The logarithm of 1000 with base 10 is always 3. This is because 10 to the power of 3 is 1000.
Math.Pow
Finally You can duplicate the effects of Log10 with Log by passing 10 as the second argument.
using System; class Program { static void Main() { double a = Math.Log(1); Console.WriteLine(a); // Ten to the power of 3 is 1000. double b = Math.Log10(1000); Console.WriteLine(b); double c = Math.Log(1000, 10); Console.WriteLine(c); } }
0 3 3
Uses. These methods are used for scientific formulas. Developing a fractal generator in the C# language would be interesting, and it would involve logarithms.
Summary. The Math.Log and Math.Log10 methods provide accurate results for logarithms in the C# language. They are built into .NET—they can be used directly.
C#VB.NETPythonGolangJavaSwiftRust
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Oct 11, 2022 (image).
Home
Changes
© 2007-2023 Sam Allen.