expm1, expm1f, expm1l
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |   定义于头文件  <math.h>
  | 
||
|   float       expm1f( float arg );  | 
(1) | (C99 起) | 
|   double      expm1( double arg );  | 
(2) | (C99 起) | 
|   long double expm1l( long double arg );  | 
(3) | (C99 起) | 
|   定义于头文件  <tgmath.h>
  | 
||
|   #define expm1( arg )  | 
(4) | (C99 起) | 
4) 泛型宏:若 
arg 拥有 long double 类型,则调用 expm1l 。否则,若 arg 拥有整数类型或 double 类型,则调用 expm1 。否则调用 expm1f 。参数
| arg | - | 浮点值 | 
返回值
若不出现错误则返回 earg
-1 。
若出现上溢所致的值域错误,则返回 +HUGE_VAL 、 +HUGE_VALF 或 +HUGE_VALL 。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点算术( IEC 60559 ),则
- 若参数为 ±0 ,则返回不修改的参数
 - 若参数为 -∞ ,则返回 -1
 - 若参数为 +∞ ,则返回 +∞
 - 若参数为 NaN ,则返回 NaN
 
注意
函数 expm1 和 log1p 对于金融计算有用:例如在计算小的日利率时: (1+x)n
-1 能表示为 expm1(n * log1p(x)) 。这些函数亦简化书写精确的反双曲函数。
对于 IEEE 兼容的 double 类型,若 709.8 < arg 则保证上溢。
注意
运行此代码
#include <stdio.h> #include <math.h> #include <float.h> #include <errno.h> #include <fenv.h> #pragma STDC FENV_ACCESS ON int main(void) { printf("expm1(1) = %f\n", expm1(1)); printf("Interest earned in 2 days on $100, compounded daily at 1%%\n" " on a 30/360 calendar = %f\n", 100*expm1(2*log1p(0.01/360))); printf("exp(1e-16)-1 = %g, but expm1(1e-16) = %g\n", exp(1e-16)-1, expm1(1e-16)); // 特殊值 printf("expm1(-0) = %f\n", expm1(-0.0)); printf("expm1(-Inf) = %f\n", expm1(-INFINITY)); // 错误处理 errno = 0; feclearexcept(FE_ALL_EXCEPT); printf("expm1(710) = %f\n", expm1(710)); if(errno == ERANGE) perror(" errno == ERANGE"); if(fetestexcept(FE_OVERFLOW)) puts(" FE_OVERFLOW raised"); }
可能的输出:
expm1(1) = 1.718282
Interest earned in 2 days on $100, compounded daily at 1%
 on a 30/360 calendar = 0.005556
exp(1e-16)-1 = 0, but expm1(1e-16) = 1e-16
expm1(-0) = -0.000000
expm1(-Inf) = -1.000000
expm1(710) = inf
    errno == ERANGE: Result too large
    FE_OVERFLOW raised引用
- C11 standard (ISO/IEC 9899:2011):
 
- 7.12.6.3 The expm1 functions (p: 243)
 
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
 
- F.10.3.3 The expm1 functions (p: 521)
 
- C99 standard (ISO/IEC 9899:1999):
 
- 7.12.6.3 The expm1 functions (p: 223-224)
 
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
 
- F.9.3.3 The expm1 functions (p: 458)
 
参阅
|    (C99)(C99)  | 
   计算 e 的给定次幂 ( ex )   (函数)  | 
|    (C99)(C99)(C99)  | 
   计算 2 的给定次幂( 2x )   (函数)  | 
|    (C99)(C99)(C99)  | 
   计算给定数加 1 的自然对数(底为 e )( ln(1+x) )  (函数)  |