logb()函数以及C ++中的示例

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值