Die Funktion logb () in C ++ gibt den Logarithmus von | x | zurück, wobei FLT_RADIX als Basis für den Logarithmus verwendet wird.
Im Allgemeinen ist FLT_RADIX 2, daher entspricht logb () für positive Werte log2 ().
Die Funktion ist in der Header-Datei definiert.
logb () Prototyp (Stand C ++ 11 Standard)
double logb (double x); float logb (float x); langes doppeltes logb (langes doppeltes x); doppeltes logb (T x); // Für integralen Typ
Die logb () Funktion nimmt ein einziges Argument und gibt einen Wert des Typs double
, float
oder long double
.
logb () Parameter
Die Funktion ilogb () verwendet ein einzelnes Argument, dessen Protokoll berechnet wird.
logb () Rückgabewert
Die Funktion logb () gibt den Logarithmus von | x | zurück, wobei FLT_RADIX als Basis für den Logarithmus verwendet wird.
Wenn x Null ist, kann dies abhängig von der Bibliotheksimplementierung einen Domänenfehler oder einen Polfehler oder keinen Fehler verursachen.
Beispiel 1: Wie funktioniert die Funktion logb () in C ++?
#include #include using namespace std; int main () ( double x = 121.056, result; result = logb(x); cout << "logb(" << x << ") = " << "log(|" << x << "|) = "<< result << endl; return 0; )
Wenn Sie das Programm ausführen, lautet die Ausgabe wie folgt:
logb (121.056) = log (| 121.056 |) = 6
Beispiel 2: logb () -Funktion mit ganzzahligem Typ
#include #include using namespace std; int main () ( double result; int x = -5; result = logb (x); cout << "logb(" << x << ") = " << "log(|" << x << "|) = "<< result << endl; return 0; )
Wenn Sie das Programm ausführen, lautet die Ausgabe wie folgt:
logb (-5) = log (| -5 |) = 2