C ++ logb () - C ++ standaardbibliotheek

De functie logb () in C ++ retourneert de logaritme van | x |, met FLT_RADIX als basis voor de logaritme.

Over het algemeen is FLT_RADIX 2, dus logb () is gelijk aan log2 () voor positieve waarden.

De functie is gedefinieerd in het header-bestand.

logb () prototype (vanaf C ++ 11-standaard)

dubbele logb (dubbele x); zweven logb (zweven x); lange dubbele stam (lange dubbele x); dubbele logb (T x); // Voor integraal type

De functie logb () accepteert één argument en retourneert de waarde van het type double, floatof long double.

logb () Parameters

De functie ilogb () accepteert één argument waarvan de logb wordt berekend.

logb () Retourwaarde

De functie logb () retourneert de logaritme van | x |, waarbij FLT_RADIX als basis voor de logaritme wordt gebruikt.

Als x nul is, kan dit een domeinfout of een poolfout of geen fout veroorzaken, afhankelijk van de bibliotheekimplementatie.

Voorbeeld 1: Hoe werkt de logb () -functie 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; ) 

Wanneer u het programma uitvoert, is de uitvoer:

 logb (121.056) = logboek (| 121.056 |) = 6 

Voorbeeld 2: logb () functie met integraal type

 #include #include using namespace std; int main () ( double result; int x = -5; result = logb (x); cout << "logb(" << x << ") = " << "log(|" << x << "|) = "<< result << endl; return 0; ) 

Wanneer u het programma uitvoert, is de uitvoer:

 logb (-5) = logboek (| -5 |) = 2 

Interessante artikelen...