MathF.Log() Method in C# with Examples Last Updated : 04 Apr, 2019 Comments Improve Suggest changes Like Article Like Report In C#, MathF.Log() is a MathF class method. It is used to return the logarithm of a specified number. This method can be overloaded by changing the number of the arguments passed. There are total 2 methods in the overload list of the MathF.Log() method as follows: MathF.Log(Single) Method MathF.Log(Single, Single) Method MathF.Log(Single) Method This method is used to return the natural (base e) logarithm of a specified number. Syntax: public static float Log (float x); Here, x is the specified number whose natural (base e) logarithm to be calculated and its type is System.Single. Return Value: Returns the natural logarithm of x and its type is System.Single. Note: Parameter x is always specified as a base 10 number. The return value is depend on the argument passed. Below are some cases: If the argument is positive then method will return the natural logarithm or loge(val). If the argument is zero, then the result is NegativeInfinity. If the argument is Negative(less than zero) or equal to NaN, then the result is NaN. If the argument is PositiveInfinity, then the result is PositiveInfinity. If the argument is NegativeInfinity, then the result is NaN. Example: CSharp // C# program to demonstrate working // of MathF.Log(Single) method using System; class Geeks { // Main Method public static void Main(String[] args) { // Single values whose logarithm // to be calculated float a = 9.78f; float b = 0f; float c = -4.56f; float nan = Single.NaN; float positiveInfinity = Single.PositiveInfinity; float negativeInfinity = Single.NegativeInfinity; // Input is positive number so output // will be logarithm of number Console.WriteLine(MathF.Log(a)); // positive zero as argument, so output // will be -Infinity Console.WriteLine(MathF.Log(b)); // Input is negative number so output // will be NaN Console.WriteLine(MathF.Log(c)); // Input is NaN so output // will be NaN Console.WriteLine(MathF.Log(nan)); // Input is PositiveInfinity so output // will be Infinity Console.WriteLine(MathF.Log(positiveInfinity)); // Input is NegativeInfinity so output // will be NaN Console.WriteLine(MathF.Log(negativeInfinity)); } } Output: 2.280339 -Infinity NaN NaN Infinity NaN Math.Log(Single, Single) Method This method is used to return the logarithm of a specified number in a specified base. Syntax: public static float Log (float x, float y); Parameters: x: It is the specified number whose logarithm to be calculated and its type is System.Single. y: It is the base of the logarithm of type System.Single. Return Value: It returns the logarithm of x and its type is System.Single. Note: The return value is always depend on the argument passed. Below table depicts the different cases: val base Returned Value val > 0 (0 < Base < 1) or(Base > 1) logbase(val) val < 0 any value NaN any value base < 0 NaN val != 1 base = 0 NaN val != 1 base = +ve Infinity NaN val = NaN any value NaN any value base = NaN NaN any value base = 1 NaN val = 0 (0 < Base < 1) +ve Infinity val = 0 base > 1 -ve Infinity val = +ve Infinity (0 < Base < 1) -ve Infinity val = +ve Infinity base > 1 +ve Infinity val = 1 base = 0 0 val = 1 base = +ve Infinity 0 Example: CSharp // C# program to demonstrate working // of MathF.Log(Single, Single) method using System; class Geeks { // Main Method public static void Main(String[] args) { // Here val = 4.4f and base is 0.4f then // output will be logarithm of given value Console.WriteLine(MathF.Log(4.4f, 0.4f)); // Here val is 0.5f and base > 1f then output // will be -0.5f Console.WriteLine(MathF.Log(0.5f, 4f)); // Here val is 0.9f and base = 1f then output // will be NaN Console.WriteLine(MathF.Log(0.9f, 1f)); // Here val is 0.4f and base is NaN then output // will be NaN Console.WriteLine(MathF.Log(0.4f, Single.NaN)); } } Output: -1.616959 -0.5 NaN NaN Comment More infoAdvertise with us Next Article MathF.Floor() Method in C# with Examples K Kirti_Mangal Follow Improve Article Tags : C# CSharp-method CSharp-MathF-Class Similar Reads MathF.Log10() Method in C# with Examples In C#, MathF.Log10(Single) is a MathF class method. It is used to return the base 10 logarithm of a specified number. Syntax: public static float Log10 (float x); Here, x is the specified number whose logarithm to be calculated and its type is System.Single. Return Value: It returns the logarithm of 2 min read MathF.Pow() Method in C# with Examples In C#, MathF.Pow(Single, Single) is a MathF class method. This method is used to calculate a number raise to the power of some other number. Syntax: public static float Pow (float x, float y); Parameters: x: It is a single-precision floating-point number which is to be raised to a power and type of 2 min read MathF.Exp() Method in C# with Examples In C#, Exp(Single) is a MathF class method which is used to return the e raised to the specified power. Here e is a mathematical constant whose value is approximately 2.71828. Syntax: public static float Exp (float x); Here, x is the required number of type System.Single which specifies a power. Ret 1 min read MathF.Sqrt() Method in C# with Examples In C#, MathF.Sqrt(Single) is a MathF class(present in system namespace) method which is used to calculate the square root of the specified Single or float data type value. Syntax: public static float Sqrt (float x); Here, x is the number whose square root is to be calculated and type of this paramet 2 min read MathF.Floor() Method in C# with Examples In C#, MathF.Floor(Single) is a MathF class method. This method is used to find the largest integer , which is less than or equal to the specified float value in the argument list. Syntax: public static float Floor (float x); Here, x is the float(Single) value whose floor value has to be calculated. 2 min read MathF.Ceiling() Method in C# with Examples In C#, MathF.Ceiling(Single) is a MathF class method. This method is used to find the smallest integer , which is greater than or equal to the specified single or float value in the argument list. Syntax: public static float Ceiling (float x); Here, x is the float(Single) value whose ceiling value h 1 min read Like