Namespaces
Variants

exp2, exp2f, exp2l

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

Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
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
Arguments and return values
Error handling
Fast operation indicators
Definiert in Header <math.h>
float exp2f ( float n ) ;
(1) (seit C99)
double exp2 ( double n ) ;
(2) (seit C99)
long double exp2l ( long double n ) ;
(3) (seit C99)
Definiert in Header <tgmath.h>
#define exp2( n )
(4) (seit C99)
1-3) Berechnet 2 hoch der gegebenen Potenz n .
4) Typgenerisches Makro: Wenn n den Typ long double hat, wird exp2l aufgerufen. Andernfalls, wenn n einen ganzzahligen Typ oder den Typ double hat, wird exp2 aufgerufen. Andernfalls wird exp2f aufgerufen.

Inhaltsverzeichnis

Parameter

n - Fließkommawert

Rückgabewert

Wenn keine Fehler auftreten, wird die Basis- 2 -Exponentialfunktion von n ( 2 n
) zurückgegeben.

Wenn ein Bereichsfehler aufgrund von Überlauf auftritt, +HUGE_VAL , +HUGE_VALF , oder +HUGE_VALL wird zurückgegeben.

Wenn ein Bereichsfehler aufgrund von Unterlauf auftritt, wird das korrekte Ergebnis (nach Rundung) zurückgegeben.

Fehlerbehandlung

Fehler werden gemeldet, wie in math_errhandling spezifiziert.

Wenn die Implementierung IEEE-Gleitkommaarithmetik (IEC 60559) unterstützt,

  • Wenn das Argument ±0 ist, wird 1 zurückgegeben
  • Wenn das Argument -∞ ist, wird +0 zurückgegeben
  • Wenn das Argument +∞ ist, wird +∞ zurückgegeben
  • Wenn das Argument NaN ist, wird NaN zurückgegeben

Beispiel

#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 values
    printf("exp2(-0.9) = %f\n", exp2(-0.9));
    printf("exp2(-Inf) = %f\n", exp2(-INFINITY));
    //error handling
    errno = 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");
}

Mögliche Ausgabe:

exp2(5) = 32.000000
exp2(0.5) = 1.414214
exp2(-4) = 0.062500
exp2(-0.9) = 0.535887
exp2(-Inf) = 0.000000
exp2(1024) = Inf
    errno == ERANGE: Ergebnis zu groß
    FE_OVERFLOW ausgelöst

Referenzen

  • C23-Standard (ISO/IEC 9899:2024):
  • 7.12.6.2 Die exp2-Funktionen (S.: TBD)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S.: TBD)
  • F.10.3.2 Die exp2-Funktionen (S.: TBD)
  • C17-Standard (ISO/IEC 9899:2018):
  • 7.12.6.2 Die exp2-Funktionen (S. 177)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S. 272-273)
  • F.10.3.2 Die exp2-Funktionen (S. 379)
  • C11-Standard (ISO/IEC 9899:2011):
  • 7.12.6.2 Die exp2-Funktionen (S. 242-243)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S. 373-375)
  • F.10.3.2 Die exp2-Funktionen (S. 521)
  • C99-Standard (ISO/IEC 9899:1999):
  • 7.12.6.2 Die exp2-Funktionen (S. 223)
  • 7.22 Typgenerische Mathematik <tgmath.h> (S. 335-337)
  • F.9.3.2 Die exp2-Funktionen (S. 458)

Siehe auch

(C99) (C99)
berechnet e hoch der gegebenen Potenz ( e x )
(Funktion)
(C99) (C99) (C99)
berechnet e hoch der gegebenen Potenz minus eins ( e x -1 )
(Funktion)
(C99) (C99) (C99)
berechnet den Logarithmus zur Basis 2 ( log 2 (x) )
(Funktion)