Home C&C++函数库 c++ 语法 程序源码 Linux C库

exp2

函数  <cmath> <ctgmath>

C99 double exp2 (double x);
float exp2f (float x);
long double exp2l (long double x);
C++11 double exp2 (double x);
float exp2 (float x);
long double exp2 (long double x);
double exp2 (T x);     // additional overloads for integral types

计算以2为底的指数函数
返回以2为底的x的指数函数,即2的x次方: 2x
C99 头文件<tgmath.h> 提供了该函数的泛型类型宏版本。
C++11 这个头文件(<cmath>)为整型提供了额外的重载:这些重载在计算之前将x转换为double (在T是任何整型时定义)。

☲  参数


x
指数的值。

☉  返回值



2的x次方。
如果结果的值太大,无法用返回类型的值表示, 则该函数返回带有正确符号的HUGE_VAL (或HUGE_VALFHUGE_VALL),并发生溢出范围错误:
如果出现溢出范围错误:
-并且math_errhandling设置了MATH_ERRNO: 全局变量errno设置为 ERANGE。
-并且math_errhandling设置了MATH_ERREXCEPT: 触发 FE_OVERFLOW

☣  示例



/* exp2 example */
#include <stdio.h>      /* printf */
#include <math.h>       /* exp2 */

int main ()
{
  double param, result;
  param = 8.0;
  result = exp2 (param);
  printf ("2 ^ %f = %f.\n", param, result );
  return 0;
}

输出:
2 ^ 8.000000 is 256.000000.

🍄  另请参阅



log2 计算对数(function )
pow 幂(function )
exp 计算指数(function )

联系我们 免责声明 关于CandCplus 网站地图