The MathF.Log() method in C# is used to return the logarithm of a specified number.
Syntax
Following is the syntax −
public static float Log (float val);
Above, Val is the specified number whose natural (base e) logarithm to be calculated.
Example
Let us now see an example to implement the MathF.Log() method −
using System;
public class Demo {
public static void Main(){
float val1 = 0.0f;
float val2 = 1.0f;
Console.WriteLine(MathF.Log(val1));
Console.WriteLine(MathF.Log(val2));
}
}Output
This will produce the following output −
-Infinity 0
Example
Let us now see another example to implement the MathF.Log() method −
using System;
public class Demo {
public static void Main(){
float val1 = 45.9f;
float val2 = -4.35f;
Console.WriteLine(MathF.Log(val1));
Console.WriteLine(MathF.Log(val2));
}
}Output
This will produce the following output −
3.826465 NaN