log
, logf
, logl
, log10
, log10f
, log10l
Berechnet die Logarithmen.
Syntax
double log(double x);
float logf(float x);
long double logl(double x);
double log10(double x);
float log10f (float x);
long double log10l(double x);
#define log(X) // Requires C11 or higher
#define log10(X) // Requires C11 or higher
float log(float x); // C++ only
long double log(long double x); // C++ only
float log10(float x); // C++ only
long double log10(long double x); // C++ only
Parameter
x
Ein Wert, dessen Logarithmus gesucht wird.
Rückgabewert
Die log
Funktionen geben bei erfolgreicher Ausführung den natürlichen Logarithmus (Basis e
) x
zurück. Die log10
Funktionen geben den Logarithmus base-10 zurück. Wenn x
dies negativ ist, geben diese Funktionen standardmäßig eine unbestimmte () ZurückIND
. Wenn x
0 ist, kehren sie unendlich (INF
).
Eingabe | SEH-Ausnahme | _matherr -Ausnahme |
---|---|---|
± QNaN, IND | Keine | _DOMAIN |
± 0 | ZERODIVIDE |
_SING |
x < 0 |
INVALID |
_DOMAIN |
log
und log10
verfügen über eine Implementierung, die Streaming SIMD Extensions 2 (SSE2) verwendet. Informationen und Einschränkungen bei der Verwendung der SSE2-Implementierung finden Sie _set_SSE2_enable
unter .
Hinweise
C++ ermöglicht die Überladung, sodass Sie Überladungen aufrufen und log10
diese log
annehmen und zurückgeben oder long double
Werte zurückgeben float
können. In einem C-Programm, es sei denn, Sie verwenden das <tgmath.h>
Makro, um diese Funktion aufzurufen, log
und log10
nehmen und geben Sie immer ein double
.
Wenn Sie das <tgmath.h> log()
Makro verwenden, bestimmt der Typ des Arguments, welche Version der Funktion ausgewählt ist. Ausführliche Informationen finden Sie unter "Typgenerika" .
Standardmäßig gilt der globale Zustand dieser Funktion für die Anwendung. Informationen zum Ändern dieses Verhaltens finden Sie im Global state in the CRT.
Anforderungen
Routine | Erforderlicher Header |
---|---|
log , logf , logl , log10 , log10f , log10l |
<math.h> |
log -Makro |
<tgmath.h> |
Weitere Informationen zur Kompatibilität finden Sie unter Kompatibilität.
Beispiel
// crt_log.c
/* This program uses log and log10
* to calculate the natural logarithm and
* the base-10 logarithm of 9,000.
*/
#include <math.h>
#include <stdio.h>
int main( void )
{
double x = 9000.0;
double y;
y = log( x );
printf( "log( %.2f ) = %f\n", x, y );
y = log10( x );
printf( "log10( %.2f ) = %f\n", x, y );
}
log( 9000.00 ) = 9.104980
log10( 9000.00 ) = 3.954243
Verwenden Sie zum Generieren von Logarithmen für anderen Basen die mathematische Beziehung: Logarithmische Basis b von a = Natürlicher Logarithmus (a) / Natürlicher Logarithmus (b).
// logbase.cpp
#include <math.h>
#include <stdio.h>
double logbase(double a, double base)
{
return log(a) / log(base);
}
int main()
{
double x = 65536;
double result;
result = logbase(x, 2);
printf("Log base 2 of %lf is %lf\n", x, result);
}
Log base 2 of 65536.000000 is 16.000000
Siehe auch
Mathematische und Gleitkommaunterstützung
exp
, expf
, expl
_matherr
pow
, powf
, powl
_CIlog
_CIlog10
\
Feedback
https://aka.ms/ContentUserFeedback.
Bald verfügbar: Im Laufe des Jahres 2024 werden wir GitHub-Issues stufenweise als Feedbackmechanismus für Inhalte abbauen und durch ein neues Feedbacksystem ersetzen. Weitere Informationen finden Sie unterFeedback senden und anzeigen für