System.Math.Log 方法 (Double, Double)

方法描述

返回指定数字在使用指定底时的对数。

语法定义(C# System.Math.Log 方法 (Double, Double) 的用法)

public static double Log(
	double a,
	double newBase
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
a System-Double 要查找其对数的数字。
newBase System-Double 对数的底。
返回值 System.Double 下表中的值之一。 (+Infinity 表示 PositiveInfinity,-Infinity 表示 NegativeInfinity,NaN 表示 NaN。) a newBase a > 0 (0 1) lognewBase(a) a < 0 (任意值) NaN (任意值) newBase < 0 NaN a != 1 newBase = 0 NaN a != 1 newBase = +Infinity NaN a = NaN (任意值) NaN (任意值) newBase = NaN NaN (任意值) newBase = 1 NaN a = 0 0 1 -Infinity a = +Infinity 0 1 +Infinity a = 1 newBase = 0 0 a = 1 newBase = +Infinity 0

提示和注释

System.Math.Log 方法 (Double, Double)例子

下面的示例使用 Log 计算所选值的特定对数恒等式。

// Example for the Math.Log( double ) and Math.Log( double, double ) methods.
using System;

class LogDLogDD
{
    public static void Main() 
    {
        Console.WriteLine( 
            "This example of Math.Log( double ) and " +
            "Math.Log( double, double )\n" +
            "generates the following output.\n" );
        Console.WriteLine( 
            "Evaluate these identities with " +
            "selected values for X and B (base):" );
        Console.WriteLine( "   log(B)[X] == 1 / log(X)[B]" );
        Console.WriteLine( "   log(B)[X] == ln[X] / ln[B]" );
        Console.WriteLine( "   log(B)[X] == log(B)[e] * ln[X]" );

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

    // Evaluate logarithmic identities that are functions of two arguments.
    static void UseBaseAndArg(double argB, double argX)
    {
        // Evaluate log(B)[X] == 1 / log(X)[B].
        Console.WriteLine( 
            "\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) );

        // Evaluate log(B)[X] == ln[X] / ln[B].
        Console.WriteLine( 
            "        Math.Log({1}) / Math.Log({0}) == {2:E16}",
            argB, argX, Math.Log(argX) / Math.Log(argB) );

        // Evaluate log(B)[X] == log(B)[e] * ln[X].
        Console.WriteLine( 
            "Math.Log(Math.E, {0}) * Math.Log({1}) == {2:E16}", 
            argB, argX, Math.Log(Math.E, argB) * Math.Log(argX) );
    }
}

/*
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
*/

异常

异常 异常描述

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1 受以下版本支持:

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。