This documentation is archived and is not being maintained.

Math.Log Method (Double)

Updated: April 2009

Returns the natural (base e) logarithm of a specified number.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static double Log(
	double d
)

Parameters

d
Type: System.Double

A number whose logarithm is to be found.

Return Value

Type: System.Double

Sign of d

Returns

Positive

The natural logarithm of d; that is, ln d, or log e d

Zero

NegativeInfinity

Negative

NaN

If d is equal to NaN, returns NaN. If d is equal to PositiveInfinity, returns PositiveInfinity.

Parameter d is specified as a base 10 number.

The following example illustrates the Log method.

using System;
public class Example
{
   public static void Main()
   {
      Console.WriteLine("  Evaluate this identity with selected values for X:");
      Console.WriteLine("                              ln(x) = 1 / log[X](B)");
      Console.WriteLine();

      double[] XArgs = { 1.2, 4.9, 9.9, 0.1 };

      foreach (double argX in XArgs)
      {
         // Find natural log of argX.
         Console.WriteLine("                      Math.Log({0}) = {1:E16}",
                           argX, Math.Log(argX));

         // Evaluate 1 / log[X](e).
         Console.WriteLine("             1.0 / Math.Log(e, {0}) = {1:E16}",
                           argX, 1.0 / Math.Log(Math.E, argX));
         Console.WriteLine();
      }
   }   
}
// This example displays the following output: 
//         Evaluate this identity with selected values for X: 
//                                     ln(x) = 1 / log[X](B) 
//        
//                             Math.Log(1.2) = 1.8232155679395459E-001 
//                    1.0 / Math.Log(e, 1.2) = 1.8232155679395459E-001 
//        
//                             Math.Log(4.9) = 1.5892352051165810E+000 
//                    1.0 / Math.Log(e, 4.9) = 1.5892352051165810E+000 
//        
//                             Math.Log(9.9) = 2.2925347571405443E+000 
//                    1.0 / Math.Log(e, 9.9) = 2.2925347571405443E+000 
//        
//                             Math.Log(0.1) = -2.3025850929940455E+000 
//                    1.0 / Math.Log(e, 0.1) = -2.3025850929940455E+000

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Date

History

Reason

April 2009

Replaced the example.

Customer feedback.

Show: