安卓log.e函数打印示例_C ++中带示例的log2()函数

安卓log.e函数打印示例

C ++ log2()函数 (C++ log2() function)

log2() function is a library function of cmath header, it is used to get the binary logarithm (the base-2 logarithm) of the given value. It accepts a value (float, double, or long double) and returns the binary logarithm.

log2()函数cmath标头的库函数,用于获取给定值的二进制对数(以2为底的对数)。 它接受一个值( float , double或long double )并返回二进制对数。

Syntax of log2() function:

log2()函数的语法:

C++11:

C ++ 11:

     double log2 (double x);
      float log2 (float x);
long double log2 (long double x);
     double log2 (T x);

Parameter(s):

参数:

  • x – represents the value whose binary logarithm to be found.

    x –表示要找到其二进制对数的值。

Return value:

返回值:

It returns the binary logarithm of the given value x.

它返回给定值x的二进制对数。

Note:

注意:

  • If the given value is negative, it causes a domain error.

    如果给定值为负,则将导致域错误。

  • If the given value is zero, it may cause a pole error.

    如果给定值为零,则可能导致极点错误。

Example:

例:

    Input:
    float x = 2.0f
    
    Function call:
    log2(x);
    
    Output:
    1

C ++代码演示log2()函数的示例 (C++ code to demonstrate the example of log2() function)

// C++ code to demonstrate the example of
// log2() function

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    float x = 0.0f;

    x = 10.0f;
    cout << "log2(" << x << "): " << log2(x) << endl;

    x = 2.0f;
    cout << "log2(" << x << "): " << log2(x) << endl;

    x = 20.0f;
    cout << "log2(" << x << "): " << log2(x) << endl;

    x = -10.4f;
    cout << "log2(" << x << "): " << log2(x) << endl;

    x = 0.0f;
    cout << "log2(" << x << "): " << log2(x) << endl;

    x = 100.6f;
    cout << "log2(" << x << "): " << log2(x) << endl;

    return 0;
}

Output

输出量

log2(10): 3.32193
log2(2): 1
log2(20): 4.32193
log2(-10.4): nan
log2(0): -inf
log2(100.6): 6.65249

Reference: C++ log2() function

参考: C ++ log2()函数

翻译自: https://www.includehelp.com/cpp-tutorial/log2-function-with-example.aspx

安卓log.e函数打印示例

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值