Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      exp2, exp2f, exp2l

      From cppreference.com
      <c‎ |numeric‎ |math
       
       
       
      Common mathematical functions
      Functions
      Basic operations
      (C99)
      (C99)
      (C99)
      (C99)(C99)(C99)(C23)
      Maximum/minimum operations
      (C99)
      (C99)
      Exponential functions
      (C23)
      exp2
      (C99)
      (C99)
      (C23)
      (C23)

      (C99)
      (C99)(C23)
      (C23)
      (C23)
      Power functions
      (C99)
      (C23)
      (C23)

      (C99)
      (C23)
      (C23)
      Trigonometric and hyperbolic functions
      (C23)
      (C23)
      (C23)
      (C23)
      (C99)
      (C99)
      (C99)
      Nearest integer floating-point
      (C99)(C99)(C99)
      (C23)(C23)(C23)(C23)
      Floating-point manipulation
      (C99)(C99)
      (C99)(C23)
      (C99)
      Narrowing operations
      (C23)
      (C23)
      (C23)
      (C23)
      (C23)
      (C23)
      Quantum and quantum exponent
      Decimal re-encoding functions
      Total order and payload functions
      Classification
      Error and gamma functions
      (C99)
      (C99)
      (C99)
      (C99)
      Types
      Macro constants
      Special floating-point values
      (C99)(C23)
      Arguments and return values
      Error handling
      Fast operation indicators
       
      Defined in header<math.h>
      float       exp2f(float n);
      (1)(since C99)
      double      exp2(double n);
      (2)(since C99)
      longdouble exp2l(longdouble n);
      (3)(since C99)
      Defined in header<tgmath.h>
      #define exp2( n )
      (4)(since C99)
      1-3) Computes 2 raised to the given powern.
      4) Type-generic macro: Ifn has typelongdouble,exp2l is called. Otherwise, ifn has integer type or the typedouble,exp2 is called. Otherwise,exp2f is called.

      Contents

      [edit]Parameters

      n - floating-point value

      [edit]Return value

      If no errors occur, the base-2 exponential ofn (2n
      ) is returned.

      If a range error due to overflow occurs,+HUGE_VAL,+HUGE_VALF, or+HUGE_VALL is returned.

      If a range error occurs due to underflow, the correct result (after rounding) is returned.

      [edit]Error handling

      Errors are reported as specified inmath_errhandling.

      If the implementation supports IEEE floating-point arithmetic (IEC 60559),

      • If the argument is ±0, 1 is returned
      • If the argument is -∞, +0 is returned
      • If the argument is +∞, +∞ is returned
      • If the argument is NaN, NaN is returned

      [edit]Example

      Run this code
      #include <errno.h>#include <fenv.h>#include <float.h>#include <math.h>#include <stdio.h>// #pragma STDC FENV_ACCESS ON int main(void){printf("exp2(5) = %f\n", exp2(5));printf("exp2(0.5) = %f\n", exp2(0.5));printf("exp2(-4) = %f\n", exp2(-4));// special valuesprintf("exp2(-0.9) = %f\n", exp2(-0.9));printf("exp2(-Inf) = %f\n", exp2(-INFINITY));//error handlingerrno=0;feclearexcept(FE_ALL_EXCEPT);printf("exp2(1024) = %f\n", exp2(1024));if(errno==ERANGE)perror("    errno == ERANGE");if(fetestexcept(FE_OVERFLOW))puts("    FE_OVERFLOW raised");}

      Possible output:

      exp2(5) = 32.000000exp2(0.5) = 1.414214exp2(-4) = 0.062500exp2(-0.9) = 0.535887exp2(-Inf) = 0.000000exp2(1024) = Inf    errno == ERANGE: Result too large    FE_OVERFLOW raised

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 7.12.6.2 The exp2 functions (p: TBD)
      • 7.25 Type-generic math <tgmath.h> (p: TBD)
      • F.10.3.2 The exp2 functions (p: TBD)
      • C17 standard (ISO/IEC 9899:2018):
      • 7.12.6.2 The exp2 functions (p: 177)
      • 7.25 Type-generic math <tgmath.h> (p: 272-273)
      • F.10.3.2 The exp2 functions (p: 379)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.12.6.2 The exp2 functions (p: 242-243)
      • 7.25 Type-generic math <tgmath.h> (p: 373-375)
      • F.10.3.2 The exp2 functions (p: 521)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.12.6.2 The exp2 functions (p: 223)
      • 7.22 Type-generic math <tgmath.h> (p: 335-337)
      • F.9.3.2 The exp2 functions (p: 458)

      [edit]See also

      (C99)(C99)
      computese raised to the given power (\({\small e^x}\)ex)
      (function)[edit]
      (C99)(C99)(C99)
      computese raised to the given power, minus one (\({\small e^x-1}\)ex-1)
      (function)[edit]
      (C99)(C99)(C99)
      computes base-2 logarithm (\({\small \log_{2}{x} }\)log2(x))
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/numeric/math/exp2&oldid=172009"

      [8]ページ先頭

      ©2009-2025 Movatter.jp