Namespaces
Variants

log, logf, logl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
log
(C99)
(C99) (C23)
(C23)
(C23)
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
Definiert im Header <math.h>
float logf ( float arg ) ;
(1) (seit C99)
double log ( double arg ) ;
(2)
long double logl ( long double arg ) ;
(3) (seit C99)
Definiert im Header <tgmath.h>
#define log( arg )
(4) (seit C99)
1-3) Berechnet den natürlichen Logarithmus (Basis e ) von arg .
4) Typgenerisches Makro: Wenn arg den Typ long double hat, wird logl aufgerufen. Andernfalls, wenn arg einen Ganzzahltyp oder den Typ double hat, wird log aufgerufen. Andernfalls wird logf aufgerufen. Wenn arg komplex oder imaginär ist, ruft das Makro die entsprechende komplexe Funktion auf ( clogf , clog , clogl ).

Inhaltsverzeichnis

Parameter

arg - Gleitkommawert

Rückgabewert

Wenn keine Fehler auftreten, wird der natürliche (Basis- e ) Logarithmus von arg ( ln(arg) oder log e (arg) ) zurückgegeben.

Wenn ein Domänenfehler auftritt, wird ein implementierungsdefinierter Wert zurückgegeben (NaN, sofern unterstützt).

Wenn ein Polfehler auftritt, -HUGE_VAL , -HUGE_VALF , oder -HUGE_VALL wird zurückgegeben.

Fehlerbehandlung

Fehler werden gemeldet, wie in math_errhandling spezifiziert.

Ein Domänenfehler tritt auf, wenn arg kleiner als null ist.

Polfehler kann auftreten, wenn arg null ist.

Wenn die Implementierung IEEE-Gleitkommaarithmetik (IEC 60559) unterstützt,

  • Wenn das Argument ±0 ist, wird -∞ zurückgegeben und FE_DIVBYZERO wird ausgelöst.
  • Wenn das Argument 1 ist, wird +0 zurückgegeben
  • Wenn das Argument negativ ist, wird NaN zurückgegeben und FE_INVALID wird ausgelöst.
  • Wenn das Argument +∞ ist, wird +∞ zurückgegeben
  • Wenn das Argument NaN ist, wird NaN zurückgegeben.

Beispiel

#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
// #pragma STDC FENV_ACCESS ON
int main(void)
{
    printf("log(1) = %f\n", log(1));
    printf("base-5 logarithm of 125 = %f\n", log(125) / log(5));
    // special values
    printf("log(1) = %f\n", log(1));
    printf("log(+Inf) = %f\n", log(INFINITY));
    // error handling
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("log(0) = %f\n", log(0));
    if (errno == ERANGE)
        perror("    errno == ERANGE");
    if (fetestexcept(FE_DIVBYZERO))
        puts("    FE_DIVBYZERO raised");
}

Ausgabe:

log(1) = 0.000000
base-5 logarithm of 125 = 3.000000
log(1) = 0.000000
log(+Inf) = inf
log(0) = -inf
    errno == ERANGE: Numerical result out of range
    FE_DIVBYZERO raised

Referenzen

  • C23-Standard (ISO/IEC 9899:2024):
  • 7.12.6.7 Die log-Funktionen (S.: TBD)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S.: TBD)
  • F.10.3.7 Die log-Funktionen (S.: TBD)
  • C17-Standard (ISO/IEC 9899:2018):
  • 7.12.6.7 Die log-Funktionen (S. 178-179)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S. 272-273)
  • F.10.3.7 Die log-Funktionen (S. 380)
  • C11-Standard (ISO/IEC 9899:2011):
  • 7.12.6.7 Die log-Funktionen (S. 244-245)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S. 373-375)
  • F.10.3.7 Die log-Funktionen (S. 522)
  • C99-Standard (ISO/IEC 9899:1999):
  • 7.12.6.7 Die log-Funktionen (S. 225)
  • 7.22 Typgenerische Mathematik <tgmath.h> (S. 335-337)
  • F.9.3.7 Die log-Funktionen (S. 459)
  • C89/C90-Norm (ISO/IEC 9899:1990):
  • 4.5.4.4 Die log-Funktion

Siehe auch

berechnet den dekadischen Logarithmus (Basis- 10 ) ( log 10 (x) )
(Funktion)
(C99) (C99) (C99)
berechnet den binären Logarithmus (Basis-2) ( log 2 (x) )
(Funktion)
(C99) (C99) (C99)
berechnet den natürlichen Logarithmus (Basis- e ) von 1 plus der gegebenen Zahl ( ln(1+x) )
(Funktion)
(C99) (C99)
berechnet e hoch die gegebene Potenz ( e x )
(Funktion)
(C99) (C99) (C99)
berechnet den komplexen natürlichen Logarithmus
(Funktion)