本文整理匯總了C#中System.Math.Log方法的典型用法代碼示例。如果您正苦於以下問題:C# Math.Log方法的具體用法?C# Math.Log怎麽用?C# Math.Log使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Math
的用法示例。
在下文中一共展示了Math.Log方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
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();
}
}
}
輸出:
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
示例2: Main
// 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) );
}
}
輸出:
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