C++ Reference: Standard C++ Library reference: C Library: cmath: expm1

发布于:2022-12-05 ⋅ 阅读:(571) ⋅ 点赞:(0)

C++官网参考链接:https://cplusplus.com/reference/cmath/expm1/

函数
<cmath> <ctgmath>
expm1
C99
double expm1(double x);      
float expm1f(float x);
long double expm1l(long double x);
C++11
double expm1(double x);      
float expm1(float x);
long double expm1(long double x);     
double expm1 (T x);  // additional overloads for integral types

计算指数减1
返回e的x次幂减1:e^x-1。 
对于x的绝对大小值较小,expm1可能比exp(x)-1更准确。
C99
头文件<tgmath.h>提供了该函数的泛型类型的宏版本。
C++11
在此头文件(<cmath>)中为整型(integral types)提供了额外的重载:这些重载在计算之前有效地将x转换为double类型(定义T为任何整型(integral type))。

形参
x
指数值。

返回值
2的x次幂减1。
如果结果的绝对大小太大,不能用返回类型的值表示,函数返回HUGE_VAL(或HUGE_VALFHUGE_VALL)和适当的符号,并发生上溢范围错误: 
如果发生上溢范围错误: 
math_errhandling具有MATH_ERRNO集合:全局变量errno设置为ERANGE
math_errhandling具有MATH_ERREXCEPT集合:引发FE_OVERFLOW。 

用例
/* expm1 example */
#include <stdio.h>      /* printf */
#include <math.h>       /* expm1 */

int main ()
{
  double param, result;
  param = 1.0;
  result = expm1 (param);
  printf ("expm1 (%f) = %f.\n", param, result );
  return 0;

输出:

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到