C# Math - Log10() Method
The C# Log10() method returns the base-10 logarithm of a given number. In special cases it returns the following:
- If the argument is NaN or less than zero, the method returns NaN.
- If the argument is positive infinity, the method returns positive infinity.
- If the argument is zero, the method returns negative infinity.
Syntax
public static double Log10 (double arg);
Parameters
arg |
Specify the number whose logarithm is to be found. |
Return Value
Returns the base-10 logarithm of a given number.
Example:
In the example below, Log10() method is used to calculate the base-10 logarithm of a given number.
using System; class MyProgram { static void Main(string[] args) { Console.WriteLine("Math.Log10(0) = " + Math.Log10(0)); Console.WriteLine("Math.Log10(10) = " + Math.Log10(10)); Console.WriteLine("Math.Log10(50) = " + Math.Log10(50)); Console.WriteLine("Math.Log10(Double.NaN) = " + Math.Log10(Double.NaN)); Console.WriteLine("Math.Log10(Double.NegativeInfinity) = " + Math.Log10(Double.NegativeInfinity)); Console.WriteLine("Math.Log10(Double.PositiveInfinity) = " + Math.Log10(Double.PositiveInfinity)); } }
The output of the above code will be:
Math.Log10(0) = -Infinity Math.Log10(10) = 1 Math.Log10(50) = 1.69897000433602 Math.Log10(Double.NaN) = NaN Math.Log10(Double.NegativeInfinity) = NaN Math.Log10(Double.PositiveInfinity) = Infinity
❮ C# Math Methods