Aracılığıyla paylaş


Math.Log Method (Double, Double)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Returns the logarithm of a specified number in a specified base.

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

Syntax

'Declaration
Public Shared Function Log ( _
    a As Double, _
    newBase As Double _
) As Double
public static double Log(
    double a,
    double newBase
)

Parameters

Return Value

Type: System.Double
One of the values in the following table. (+Infinity denotes PositiveInfinity, -Infinity denotes NegativeInfinity, and NaN denotes NaN.)

a

newBase

Return Value

a > 0

(0 <newBase< 1) -or-(newBase> 1)

lognewBase(a)

a < 0

(any value)

NaN

(any value)

newBase < 0

NaN

a != 1

newBase = 0

NaN

a != 1

newBase = +Infinity

NaN

a = NaN

(any value)

NaN

(any value)

newBase = NaN

NaN

(any value)

newBase = 1

NaN

a = 0

0 <newBase< 1

+Infinity

a = 0

newBase > 1

-Infinity

a = +Infinity

0 <newBase< 1

-Infinity

a = +Infinity

newBase > 1

+Infinity

a = 1

newBase = 0

0

a = 1

newBase = +Infinity

0

Examples

The following example uses Log to evaluate certain logarithmic identities for selected values.

' Example for the Math.Log( Double ) and Math.Log( Double, Double ) methods.

Module Example

   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      outputBlock.Text &= _
          "This example of Math.Log( Double ) and " + _
          "Math.Log( Double, Double )" & vbCrLf & _
          "generates the following output." & vbCrLf & vbCrLf
      outputBlock.Text &= _
          "Evaluate these identities with selected " & _
          "values for X and B (base):" & vbCrLf
      outputBlock.Text &= "   log(B)[X] = 1 / log(X)[B]" & vbCrLf
      outputBlock.Text &= "   log(B)[X] = ln[X] / ln[B]" & vbCrLf
      outputBlock.Text &= "   log(B)[X] = log(B)[e] * ln[X]" & vbCrLf

      UseBaseAndArg(outputBlock, 0.1, 1.2)
      UseBaseAndArg(outputBlock, 1.2, 4.9)
      UseBaseAndArg(outputBlock, 4.9, 9.9)
      UseBaseAndArg(outputBlock, 9.9, 0.1)
   End Sub 'Main

   ' Evaluate logarithmic identities that are functions of two arguments.
   Sub UseBaseAndArg(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal argB As Double, ByVal argX As Double)

      ' Evaluate log(B)[X] = 1 / log(X)[B].
      outputBlock.Text &= String.Format( _
          vbCrLf & "                   Math.Log({1}, {0}) = {2:E16}" + _
          vbCrLf & "             1.0 / Math.Log({0}, {1}) = {3:E16}", _
          argB, argX, Math.Log(argX, argB), _
          1.0 / Math.Log(argB, argX)) & vbCrLf

      ' Evaluate log(B)[X] = ln[X] / ln[B].
      outputBlock.Text &= String.Format( _
          "        Math.Log({1}) / Math.Log({0}) = {2:E16}", _
          argB, argX, Math.Log(argX) / Math.Log(argB)) & vbCrLf

      ' Evaluate log(B)[X] = log(B)[e] * ln[X].
      outputBlock.Text &= String.Format( _
          "Math.Log(Math.E, {0}) * Math.Log({1}) = {2:E16}", _
          argB, argX, Math.Log(Math.E, argB) * Math.Log(argX)) & vbCrLf

   End Sub 'UseBaseAndArg
End Module 'LogDLogDD

' This example of Math.Log( Double ) and Math.Log( Double, Double )
' generates the following output.
' 
' Evaluate these identities with selected values for X and B (base):
'    log(B)[X] = 1 / log(X)[B]
'    log(B)[X] = ln[X] / ln[B]
'    log(B)[X] = log(B)[e] * ln[X]
' 
'                    Math.Log(1.2, 0.1) = -7.9181246047624818E-002
'              1.0 / Math.Log(0.1, 1.2) = -7.9181246047624818E-002
'         Math.Log(1.2) / Math.Log(0.1) = -7.9181246047624818E-002
' Math.Log(Math.E, 0.1) * Math.Log(1.2) = -7.9181246047624804E-002
' 
'                    Math.Log(4.9, 1.2) = 8.7166610085093179E+000
'              1.0 / Math.Log(1.2, 4.9) = 8.7166610085093161E+000
'         Math.Log(4.9) / Math.Log(1.2) = 8.7166610085093179E+000
' Math.Log(Math.E, 1.2) * Math.Log(4.9) = 8.7166610085093179E+000
' 
'                    Math.Log(9.9, 4.9) = 1.4425396251981288E+000
'              1.0 / Math.Log(4.9, 9.9) = 1.4425396251981288E+000
'         Math.Log(9.9) / Math.Log(4.9) = 1.4425396251981288E+000
' Math.Log(Math.E, 4.9) * Math.Log(9.9) = 1.4425396251981288E+000
' 
'                    Math.Log(0.1, 9.9) = -1.0043839404494075E+000
'              1.0 / Math.Log(9.9, 0.1) = -1.0043839404494075E+000
'         Math.Log(0.1) / Math.Log(9.9) = -1.0043839404494075E+000
' Math.Log(Math.E, 9.9) * Math.Log(0.1) = -1.0043839404494077E+000
// Example for the Math.Log( double ) and Math.Log( double, double ) methods.
using System;

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text +=
          "This example of Math.Log( double ) and " +
          "Math.Log( double, double )\n" +
          "generates the following output.\n" + "\n";
      outputBlock.Text +=
          "Evaluate these identities with " +
          "selected values for X and B (base):" + "\n";
      outputBlock.Text += "   log(B)[X] == 1 / log(X)[B]" + "\n";
      outputBlock.Text += "   log(B)[X] == ln[X] / ln[B]" + "\n";
      outputBlock.Text += "   log(B)[X] == log(B)[e] * ln[X]" + "\n";

      UseBaseAndArg(outputBlock, 0.1, 1.2);
      UseBaseAndArg(outputBlock, 1.2, 4.9);
      UseBaseAndArg(outputBlock, 4.9, 9.9);
      UseBaseAndArg(outputBlock, 9.9, 0.1);
   }

   // Evaluate logarithmic identities that are functions of two arguments.
   static void UseBaseAndArg(System.Windows.Controls.TextBlock outputBlock, double argB, double argX)
   {
      // Evaluate log(B)[X] == 1 / log(X)[B].
      outputBlock.Text += String.Format(
          "\n                   Math.Log({1}, {0}) == {2:E16}" +
          "\n             1.0 / Math.Log({0}, {1}) == {3:E16}",
          argB, argX, Math.Log(argX, argB),
          1.0 / Math.Log(argB, argX)) + "\n";

      // Evaluate log(B)[X] == ln[X] / ln[B].
      outputBlock.Text += String.Format(
          "        Math.Log({1}) / Math.Log({0}) == {2:E16}",
          argB, argX, Math.Log(argX) / Math.Log(argB)) + "\n";

      // Evaluate log(B)[X] == log(B)[e] * ln[X].
      outputBlock.Text += String.Format(
          "Math.Log(Math.E, {0}) * Math.Log({1}) == {2:E16}",
          argB, argX, Math.Log(Math.E, argB) * Math.Log(argX)) + "\n";
   }
}

/*
This example of Math.Log( double ) and Math.Log( double, double )
generates the following output.

Evaluate these identities with selected values for X and B (base):
   log(B)[X] == 1 / log(X)[B]
   log(B)[X] == ln[X] / ln[B]
   log(B)[X] == log(B)[e] * ln[X]

                   Math.Log(1.2, 0.1) == -7.9181246047624818E-002
             1.0 / Math.Log(0.1, 1.2) == -7.9181246047624818E-002
        Math.Log(1.2) / Math.Log(0.1) == -7.9181246047624818E-002
Math.Log(Math.E, 0.1) * Math.Log(1.2) == -7.9181246047624804E-002

                   Math.Log(4.9, 1.2) == 8.7166610085093179E+000
             1.0 / Math.Log(1.2, 4.9) == 8.7166610085093161E+000
        Math.Log(4.9) / Math.Log(1.2) == 8.7166610085093179E+000
Math.Log(Math.E, 1.2) * Math.Log(4.9) == 8.7166610085093179E+000

                   Math.Log(9.9, 4.9) == 1.4425396251981288E+000
             1.0 / Math.Log(4.9, 9.9) == 1.4425396251981288E+000
        Math.Log(9.9) / Math.Log(4.9) == 1.4425396251981288E+000
Math.Log(Math.E, 4.9) * Math.Log(9.9) == 1.4425396251981288E+000

                   Math.Log(0.1, 9.9) == -1.0043839404494075E+000
             1.0 / Math.Log(9.9, 0.1) == -1.0043839404494075E+000
        Math.Log(0.1) / Math.Log(9.9) == -1.0043839404494075E+000
Math.Log(Math.E, 9.9) * Math.Log(0.1) == -1.0043839404494077E+000
*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.