Namespaces
Variants

INFINITY

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
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
INFINITY DEC_INFINITY
(C99) (C23)
(C99) (C23)
Arguments and return values
Error handling
Fast operation indicators
Definiert im Header <math.h>
#define INFINITY /*implementierungsdefiniert*/
(seit C99)

Falls die Implementierung Gleitkomma-Unendlichkeiten unterstützt, erweitert sich das Makro INFINITY zu einem konstanten Ausdruck vom Typ float , der zu positiver oder vorzeichenloser Unendlichkeit ausgewertet wird.

Wenn die Implementierung keine Gleitkomma-Unendlichkeiten unterstützt, expandiert das Makro INFINITY zu einem positiven Wert, der garantiert zur Compile-Zeit einen Überlauf in einem float verursacht, und die Verwendung dieses Makros erzeugt eine Compiler-Warnung.

Der Stil, mit dem eine Unendlichkeit ausgegeben wird, ist implementierungsdefiniert.

Beispiel

Zeigt den Stil, der zum Drucken einer Unendlichkeit und des IEEE-Formats verwendet wird.

#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
int main(void)
{
    double f = INFINITY;
    uint64_t fn; memcpy(&fn, &f, sizeof f);
    printf("INFINITY:   %f %" PRIx64 "\n", f, fn);
}

Mögliche Ausgabe:

INFINITY:   inf 7ff0000000000000

Referenzen

  • C11-Standard (ISO/IEC 9899:2011):
  • 7.12/4 INFINITY (S. 231-232)
  • C99-Standard (ISO/IEC 9899:1999):
  • 7.12/4 INFINITY (S. 212-213)

Siehe auch

(C99)
prüft, ob die gegebene Zahl unendlich ist
(Funktionsmakro)
kennzeichnet Werte, die zu groß für die Darstellung als float , double bzw. long double sind (Unendlich)
(Makrokonstante)
C++-Dokumentation für INFINITY