首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::log2

Defined in header <cmath>

?

?

float log2( float arg );

(1)

(since C++11)

double log2( double arg );

(2)

(since C++11)

long double log2( long double arg );

(3)

(since C++11)

double log2( Integral arg );

(4)

(since C++11)

1-3%29计算二进制%28碱基-%29对数arg...

4%29一组过载或接受任意参数的函数模板积分型等于2%29%28double29%。

参数

arg

-

value of floating-point or Integral type

返回值

如果没有错误发生,基地-对数arg%28日志

返回2%28 arg%29或lb%28 arg%29%29。

如果发生域错误,则返回支持%29的实现定义值%28 NaN。

如果发生极差,-HUGE_VAL,,,-HUGE_VALF,或-HUGE_VALL会被归还。

错误处理

错误按数学[医]错误处理...

在以下情况下发生域错误arg小于零。

极错误可能发生在arg是零。

如果实现支持ieee浮点算法%28IEC 60559%29,

  • 如果参数为±0,则返回-∞FE_DIVBYZERO是被抚养的。
  • 如果参数为1,则返回+0。
  • 如果参数为否定,则返回NaNFE_INVALID是被抚养的。
  • 如果参数为+∞,则返回+∞
  • 如果参数为nan,则返回nan。

注记

整型arg,二进制对数可以解释为输入中最重要的1位的基于零的索引。

二次

代码语言:javascript
复制
#include <iostream>
#include <cmath>
#include <cerrno>
#include <cstring>
#include <cfenv>
#pragma STDC FENV_ACCESS ON
int main()
{
    std::cout << "log2(65536) = " << std::log2(65536) << '\n'
              << "log2(0.125) = " << std::log2(0.125) << '\n'
              << "log2(0x020f) = " << std::log2(0x020f)
              << " (highest set bit is in position 9)\n"
              << "base-5 logarithm of 125 = " << std::log2(125)/std::log2(5) << '\n';
    // special values
    std::cout << "log2(1) = " << std::log2(1) << '\n'
              << "log2(+Inf) = " << std::log2(INFINITY) << '\n';
    // error handling 
    errno=0; std::feclearexcept(FE_ALL_EXCEPT);
    std::cout << "log2(0) = " << std::log2(0) << '\n';
    if(errno == ERANGE)
        std::cout << "    errno == ERANGE: " << std::strerror(errno) << '\n';
    if(std::fetestexcept(FE_DIVBYZERO))
        std::cout << "    FE_DIVBYZERO raised\n";
}

二次

可能的产出:

二次

代码语言:javascript
复制
log2(65536) = 16
log2(0.125) = -3
log2(0x020f) = 9.04166 (highest set bit is in position 9)
base-5 logarithm of 125 = 3
log2(1) = 0
log2(+Inf) = inf
log2(0) = -inf
    errno == ERANGE: Numerical result out of range
    FE_DIVBYZERO raised

二次

另见

log

computes natural (base e) logarithm (to base e) (ln(x)) (function)

log10

computes common (base 10) logarithm (log10(x)) (function)

log1p (C++11)

natural logarithm (to base e) of 1 plus the given number (ln(1+x)) (function)

exp2 (C++11)

returns 2 raised to the given power (2x) (function)

c日志文件2

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com