Namespaces
Variants

NAN

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
NAN DEC_NAN
(C99) (C23)
Arguments and return values
Error handling
Fast operation indicators
Definiert im Header <math.h>
#define NAN /*implementierungsdefiniert*/
(seit C99)

Das Makro NAN expandiert zu einem konstanten Ausdruck vom Typ float , der zu einem stillen "Keine-Zahl"-Wert (QNaN) ausgewertet wird. Falls die Implementierung QNaNs nicht unterstützt, ist diese Makrokonstante nicht definiert.

Der Stil, der zum Ausgeben eines NaN verwendet wird, ist implementierungsdefiniert.

Inhaltsverzeichnis

Hinweise

Es gibt viele verschiedene NaN-Werte, die durch ihre Payloads und ihre Vorzeichenbits unterschieden werden. Der Inhalt der Payload und das Vorzeichenbit des NaN, das durch das Makro NAN generiert wird, sind implementierungsdefiniert.

Beispiel

Zeigt den Stil, der zum Drucken eines NaN und IEEE-Formats verwendet wird.

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

Mögliche Ausgabe:

NAN:   nan 7ff8000000000000

Referenzen

  • C23-Standard (ISO/IEC 9899:2024):
  • 7.12/5 NAN (S.: TBD)
  • F.10/11/13 NAN (S.: TBD)
  • C17-Standard (ISO/IEC 9899:2018):
  • 7.12/5 NAN (S.: TBD)
  • F.10/11/13 NAN (S.: TBD)
  • C11-Standard (ISO/IEC 9899:2011):
  • 7.12/5 NAN (S. 232)
  • F.10/11/13 NAN (S. 518)
  • C99-Standard (ISO/IEC 9899:1999):
  • 7.12/5 NAN (S. 213)
  • F.9/11/13 NAN (S. 455)

Siehe auch

(C99) (C99) (C99)
gibt eine NaN (Not-a-Number) zurück
(Funktion)
(C99)
prüft, ob die gegebene Zahl NaN ist
(Funktionsmakro)