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

std::expm1

Defined in header <cmath>

?

?

float expm1( float arg );

(1)

(since C++11)

double expm1( double arg );

(2)

(since C++11)

long double expm1( long double arg );

(3)

(since C++11)

double expm1( Integral arg );

(4)

(since C++11)

1-3%29计算e%28欧拉%27S数,2.7182818%29提高到给定的功率arg,减1.0这个函数比表达式更精确std::exp(arg)-1.0如果arg接近于零。

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

参数

arg

-

value of floating-point or Integral type

返回值

如果没有错误发生

-1人被退回。

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

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

错误处理

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

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

  • 如果参数为±0,则返回未经修改的参数
  • 如果参数为-∞,则返回-1。
  • 如果参数为+∞,则返回+∞
  • 如果参数为nan,则返回nan。

注记

功能std::expm1std::log1p用于财务计算,例如,在计算小日利率时:%281+x%29N

-1可以表示为std::expm1(n *std::log1p(x))这些函数还简化了精确逆双曲函数的编写。

适用于ieee兼容的类型。double,如果709.8<arg,则保证溢出。

二次

代码语言:javascript
复制
#include <iostream>
#include <cmath>
#include <cerrno>
#include <cstring>
#include <cfenv>
#pragma STDC FENV_ACCESS ON
int main()
{
    std::cout << "expm1(1) = " << std::expm1(1) << '\n'
              << "Interest earned in 2 days on on $100, compounded daily at 1%\n"
              << " on a 30/360 calendar = "
              << 100*std::expm1(2*std::log1p(0.01/360)) << '\n'
              << "exp(1e-16)-1 = " << std::exp(1e-16)-1
              << ", but expm1(1e-16) = " << std::expm1(1e-16) << '\n';
    // special values
    std::cout << "expm1(-0) = " << std::expm1(-0.0) << '\n'
              << "expm1(-Inf) = " << std::expm1(-INFINITY) << '\n';
    // error handling
    errno=0; std::feclearexcept(FE_ALL_EXCEPT);
    std::cout << "expm1(710) = " << std::expm1(710) << '\n';
    if(errno == ERANGE)
        std::cout << "    errno == ERANGE: " << std::strerror(errno) << '\n';
    if(std::fetestexcept(FE_OVERFLOW))
        std::cout << "    FE_OVERFLOW raised\n";
}

二次

可能的产出:

二次

代码语言:javascript
复制
expm1(1) = 1.71828
Interest earned in 2 days on on $100, compounded daily at 1%
 on a 30/360 calendar = 0.00555563
exp(1e-16)-1 = 0 expm1(1e-16) = 1e-16
expm1(-0) = -0
expm1(-Inf) = -1
expm1(710) = inf
    errno == ERANGE: Result too large
    FE_OVERFLOW raised

二次

另见

exp

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

exp2 (C++11)

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

log1p (C++11)

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

c费用文件1

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com