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

std::exp2

Defined in header <cmath>

?

?

double exp2( double n );

(1)

(since C++11)

float exp2( float n );

(2)

(since C++11)

long double exp2( long double n );

(3)

(since C++11)

double exp2( Integral n );

(4)

(since C++11)

1-3%29计算2提升到给定的功率。n

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

参数

n

-

value of floating-point or Integral type

返回值

如果没有错误发生,基地-指数n%282n

%29被返回。

如果溢出导致范围错误,+HUGE_VAL,,,+HUGE_VALF,或+HUGE_VALL会被归还。

如果由于下流而发生范围错误,则返回舍入%29后的正确结果%28。

错误处理

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

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

  • 如果参数为±0,则返回1
  • 如果参数为-∞,则返回+0。
  • 如果参数为+∞,则返回+∞
  • 如果参数为nan,则返回nan。

二次

代码语言:javascript
复制
#include <iostream>
#include <cmath>
#include <cerrno>
#include <cstring>
#include <cfenv>
#pragma STDC FENV_ACCESS ON
int main()
{
    std::cout << "exp2(4) = " << std::exp2(4) << '\n'
              << "exp2(0.5) = " << std::exp2(0.5) << '\n'
              << "exp2(-4) = " << std::exp2(-4) << '\n';
    // special values
    std::cout << "exp2(-0) = " << std::exp2(-0.0) << '\n'
              << "exp2(-Inf) = " << std::exp2(-INFINITY) << '\n';
    // error handling 
    errno=0; std::feclearexcept(FE_ALL_EXCEPT);
    std::cout << "exp2(1024) = " << std::exp2(1024) << '\n';
    if(errno == ERANGE)
        std::cout << "    errno == ERANGE: " << std::strerror(errno) << '\n';
    if(std::fetestexcept(FE_OVERFLOW))
        std::cout << "    FE_OVERFLOW raised\n";
}

二次

可能的产出:

二次

代码语言:javascript
复制
exp2(4) = 16
exp2(0.5) = 1.41421
exp2(-4) = 0.0625
exp2(-0) = 1
exp2(-Inf) = 0
exp2(1024) = inf
    errno == ERANGE: Numerical result out of range
    FE_OVERFLOW raised

二次

另见

exp

returns e raised to the given power (ex) (function)

expm1 (C++11)

returns e raised to the given power, minus one (ex-1) (function)

log2 (C++11)

base 2 logarithm of the given number (log2(x)) (function)

c费用文件2

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com