C ++ logb()函数 (C++ logb() function)
logb() function is a library function of cmath header, it is used to get the logarithm of |given value|, where logarithm base is FLT_RADIX (On the most of the platforms the FLT_RADIX is 2, thus, logb() function is similar to log2() function for the positive values. It accepts a value (float, double, or long double) and returns the logarithm of the |given value|.
logb()函数是cmath标头的库函数,用于获取|给定值|的对数,其中对数底数为FLT_RADIX (在大多数平台上, FLT_RADIX为2,因此, logb()函数类似返回正值的log2()函数 ,它接受一个值( float , double或long double )并返回|给定值|的对数。
Syntax of logb() function:
logb()函数的语法:
C++11:
C ++ 11:
double logb (double x);
float logb (float x);
long double logb (long double x);
double logb (T x);
Parameter(s):
参数:
x – represents the value whose logarithm to be found.
x –表示要找到其对数的值。
Return value:
返回值:
It returns the logarithm of the given value |x|.
它返回给定值| x |的对数 。
Note:
注意:
If the given value is zero, it may cause a domain error or a pole error.
如果给定值为零,则可能导致域错误或极点错误。
Example:
例:
Input:
float x = 2.0f
Function call:
logb(x);
Output:
1
Input:
float x = -2.0f
Function call:
logb(x);
Output:
1
C ++代码演示logb()函数的示例 (C++ code to demonstrate the example of logb() function)
// C++ code to demonstrate the example of
// logb() function
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float x = 0.0f;
x = 10.0f;
cout << "logb(" << x << "): " << logb(x) << endl;
x = 2.0f;
cout << "logb(" << x << "): " << logb(x) << endl;
x = 20.0f;
cout << "logb(" << x << "): " << logb(x) << endl;
x = -10.4f;
cout << "logb(" << x << "): " << logb(x) << endl;
x = -2.0f;
cout << "logb(" << x << "): " << logb(x) << endl;
x = 100.6f;
cout << "logb(" << x << "): " << logb(x) << endl;
return 0;
}
Output
输出量
logb(10): 3
logb(2): 1
logb(20): 4
logb(-10.4): 3
logb(-2): 1
logb(100.6): 6
Reference: C++ logb() function
参考: C ++ logb()函数
翻译自: https://www.includehelp.com/cpp-tutorial/logb-function-with-example.aspx