Math.Log Methode

Definition

Gibt den Logarithmus der angegebenen Zahl zurück.

Überlädt

Log(Double, Double)

Gibt den Logarithmus einer angegebenen Zahl bezüglich einer angegebenen Basis zurück.

Log(Double)

Gibt den natürlichen Logarithmus (zur Basis e) der angegebenen Zahl zurück.

Log(Double, Double)

Quelle:
Math.cs
Quelle:
Math.cs
Quelle:
Math.cs

Gibt den Logarithmus einer angegebenen Zahl bezüglich einer angegebenen Basis zurück.

public:
 static double Log(double a, double newBase);
public static double Log (double a, double newBase);
static member Log : double * double -> double
Public Shared Function Log (a As Double, newBase As Double) As Double

Parameter

a
Double

Die Zahl, deren Logarithmus bestimmt werden soll.

newBase
Double

Die Basis des Logarithmus.

Gibt zurück

Einer der Werte aus der folgenden Tabelle. (Plus unendlich steht für PositiveInfinity, minus unendlich für NegativeInfinity und NaN für NaN.)

anewBase Rückgabewert
a > 0 (0 <newBase< 1) -or- (newBase> 1) lognewBase(a)
a < 0 (beliebiger Wert) NaN
(beliebiger Wert) newBase < 0 NaN
a != 1 newBase = 0 NaN
a != 1 newBase = plus unendlich NaN
a = NaN (beliebiger Wert) NaN
(beliebiger Wert) newBase = NaN NaN
(beliebiger Wert) newBase = 1 NaN
a = 0 0 <newBase< 1 plus unendlich
a = 0 newBase > 1 minus unendlich
a = plus unendlich 0 <newBase< 1 -Infinity
a = plus unendlich newBase > 1 plus unendlich
a = 1 newBase = 0 0
a = 1 newBase = plus unendlich 0

Beispiele

Im folgenden Beispiel wird verwendet Log , um bestimmte logarithmische Identitäten für ausgewählte Werte auszuwerten.

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

// Evaluate logarithmic identities that are functions of two arguments.
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 ) );
}

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 );
}

/*
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 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
*/
// Example for the Math.Log( double ) and Math.Log( double, double ) methods.
open System

// Evaluate logarithmic identities that are functions of two arguments.
let useBaseAndArg argB argX =
    // Evaluate log(B)[X] == 1 / log(X)[B].
    printfn $"""
                   Math.Log({argX}, {argB}) == {Math.Log(argX, argB):E16}
             1.0 / Math.Log({argB}, {argX}) == {1. / Math.Log(argB, argX):E16}"""

    // Evaluate log(B)[X] == ln[X] / ln[B].
    printfn $"        Math.Log({argX}) / Math.Log({argB}) == {Math.Log argX / Math.Log argB:E16}"

    // Evaluate log(B)[X] == log(B)[e] * ln[X].
    printfn $"Math.Log(Math.E, {argB}) * Math.Log({argX}) == {Math.Log(Math.E, argB) * Math.Log argX:E16}"


printfn
    """This example of Math.Log( double ) and Math.Log( double, double )
generates the following output.

printfn "Evaluate these identities with selected values for X and B (base):"""
printfn "   log(B)[X] == 1 / log(X)[B]"
printfn "   log(B)[X] == ln[X] / ln[B]" 
printfn "   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


// 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.
Module LogDLogDD
   
    Sub Main()
        Console.WriteLine( _
            "This example of Math.Log( Double ) and " + _
            "Math.Log( Double, Double )" & vbCrLf & _
            "generates the following output." & vbCrLf)
        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)
    End Sub
       
    ' Evaluate logarithmic identities that are functions of two arguments.
    Sub UseBaseAndArg(argB As Double, argX As Double)

        ' Evaluate log(B)[X] = 1 / log(X)[B].
        Console.WriteLine( _
            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))
          
        ' 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))

    End Sub
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

Hinweise

Diese Methode ruft die zugrunde liegende C-Runtime auf, und das genaue Ergebnis oder der gültige Eingabebereich kann sich zwischen verschiedenen Betriebssystemen oder Architekturen unterscheiden.

Gilt für:

Log(Double)

Quelle:
Math.cs
Quelle:
Math.cs
Quelle:
Math.cs

Gibt den natürlichen Logarithmus (zur Basis e) der angegebenen Zahl zurück.

public:
 static double Log(double d);
public static double Log (double d);
static member Log : double -> double
Public Shared Function Log (d As Double) As Double

Parameter

d
Double

Die Zahl, deren Logarithmus bestimmt werden soll.

Gibt zurück

Einer der Werte aus der folgenden Tabelle.

d-Parameter Rückgabewert
Positiv Der natürliche Logarithmus von d, d.h. ln d oder log e d
ZeroNegativeInfinity
NegativNaN
Gleich NaNNaN
Gleich PositiveInfinityPositiveInfinity

Beispiele

Im folgenden Beispiel wird die Log -Methode veranschaulicht.

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
open System

printfn "  Evaluate this identity with selected values for X:"
printfn "                              ln(x) = 1 / log[X](B)\n"

let XArgs = [| 1.2; 4.9; 9.9; 0.1 |]

for argX in XArgs do
    // Find natural log of argX.
    // The F# log function may be used instead
    printfn $"                      Math.Log({argX}) = {Math.Log argX:E16}"

    // Evaluate 1 / log[X](e).
    printfn $"             1.0 / Math.Log(e, {argX}) = {1. / Math.Log(Math.E, argX):E16}\n"

// 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
Module Example
   Sub Main()
      Console.WriteLine( _
         "  Evaluate this identity with selected values for X:")
      Console.WriteLine("                              ln(x) = 1 / log[X](B)")
      Console.WriteLine()
          
      Dim XArgs() As Double = { 1.2, 4.9, 9.9, 0.1 }
   
      For Each argX As Double 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()
      Next
   End Sub 
End Module
' 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

Hinweise

Der Parameter d wird als Basisnummer 10 angegeben.

Diese Methode ruft die zugrunde liegende C-Runtime auf, und das genaue Ergebnis oder der gültige Eingabebereich kann sich zwischen verschiedenen Betriebssystemen oder Architekturen unterscheiden.

Diese Methode ruft die zugrunde liegende C-Runtime auf, und das genaue Ergebnis oder der gültige Eingabebereich kann sich zwischen verschiedenen Betriebssystemen oder Architekturen unterscheiden.

Weitere Informationen

Gilt für: