std::exp
STD::exp
Defined in header | | |
---|---|---|
float exp( float arg | (1) | |
double exp( double arg | (2) | |
long double exp( long double arg | (3) | |
double exp( Integral arg | (4) | (since C++11) |
计算e
%28欧拉%27S数,2.7182818
%29提高到给定的功率arg
...
4%29一组过载或接受任意参数的函数模板积分型等于2%29%28double
29%。
参数
arg | - | value of floating-point or Integral type |
---|
返回值
如果没有错误发生,基地-e
指数arg
%28耳
%29被返回。
如果溢出导致范围错误,+HUGE_VAL
,,,+HUGE_VALF
,或+HUGE_VALL
会被归还。
如果由于下流而发生范围错误,则返回舍入%29后的正确结果%28。
错误处理
错误按数学[医]错误处理...
如果实现支持ieee浮点算法%28IEC 60559%29,
- 如果参数为±0,则返回1
- 如果参数为-∞,则返回+0。
- 如果参数为+∞,则返回+∞
- 如果参数为nan,则返回nan。
注记
适用于ieee兼容的类型。double,如果709.8<arg则保证溢出,如果arg<-708.4则保证下溢。
例
二次
#include <iostream>
#include <cmath>
#include <cerrno>
#include <cstring>
#include <cfenv>
#pragma STDC FENV_ACCESS ON
int main()
{
std::cout << "exp(1) = " << std::exp(1) << '\n'
<< "FV of $100, continuously compounded at 3% for 1 year = "
<< 100*std::exp(0.03) << '\n';
// special values
std::cout << "exp(-0) = " << std::exp(-0.0) << '\n'
<< "exp(-Inf) = " << std::exp(-INFINITY) << '\n';
// error handling
errno=0; std::feclearexcept(FE_ALL_EXCEPT
std::cout << "exp(710) = " << std::exp(710) << '\n';
if(errno == ERANGE)
std::cout << " errno == ERANGE: " << std::strerror(errno) << '\n';
if(std::fetestexcept(FE_OVERFLOW))
std::cout << " FE_OVERFLOW raised\n";
}
二次
可能的产出:
二次
exp(1) = 2.71828
FV of $100, continuously compounded at 3% for 1 year = 103.045
exp(-0) = 1
exp(-Inf) = 0
exp(710) = inf
errno == ERANGE: Numerical result out of range
FE_OVERFLOW raised
二次
另见
exp2 (C++11) | returns 2 raised to the given power (2x) (function) |
---|---|
expm1 (C++11) | returns e raised to the given power, minus one (ex-1) (function) |
log | computes natural (base e) logarithm (to base e) (ln(x)) (function) |
exp(std::complex) | complex base e exponential (function template) |
exp(std::valarray) | applies the function std::exp to each element of valarray (function template) |
C.EXP文件
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。