FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN
Von cppreference.com
| Definiert in Header <math.h> |
||
| #define FP_NORMAL /*implementierungsabhängig*/ |
(seit C99) | |
| #define FP_SUBNORMAL /*implementierungsabhängig*/ |
(seit C99) | |
| #define FP_ZERO /*implementierungsabhängig*/ |
(seit C99) | |
| #define FP_INFINITE /*implementierungsabhängig*/ |
(seit C99) | |
| #define FP_NAN /*implementierungsabhängig*/ |
(seit C99) | |
Die Makros FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE und FP_NAN repräsentieren jeweils eine bestimmte Kategorie von Gleitkommazahlen. Sie alle expandieren zu einem ganzzahligen konstanten Ausdruck.
| Konstante | Erklärung |
FP_NORMAL
|
zeigt an, dass der Wert eine normale Zahl ist, d.h. keine Unendlichkeit, keine Subnormale, keine Nicht-Zahl (NaN) und keine Null |
FP_SUBNORMAL
|
zeigt an, dass der Wert eine subnormale Zahl ist |
FP_ZERO
|
zeigt an, dass der Wert eine positive oder negative Null ist |
FP_INFINITE
|
zeigt an, dass der Wert durch den zugrunde liegenden Typ nicht darstellbar ist (positive oder negative Unendlichkeit) |
FP_NAN
|
zeigt an, dass der Wert eine Nicht-Zahl (NaN) ist |
[bearbeiten] Beispiel
Führen Sie diesen Code aus
#include <stdio.h> #include <math.h> #include <float.h> const char *show_classification(double x) { switch(fpclassify(x)) { case FP_INFINITE: return "Inf"; case FP_NAN: return "NaN"; case FP_NORMAL: return "normal"; case FP_SUBNORMAL: return "subnormal"; case FP_ZERO: return "zero"; default: return "unknown"; } } int main(void) { printf("1.0/0.0 is %s\n", show_classification(1/0.0)); printf("0.0/0.0 is %s\n", show_classification(0.0/0.0)); printf("DBL_MIN/2 is %s\n", show_classification(DBL_MIN/2)); printf("-0.0 is %s\n", show_classification(-0.0)); printf(" 1.0 is %s\n", show_classification(1.0)); }
Ausgabe
1.0/0.0 is Inf 0.0/0.0 is NaN DBL_MIN/2 is subnormal -0.0 is zero 1.0 is normal
[bearbeiten] Referenzen
- C17-Standard (ISO/IEC 9899:2018)
- 7.12/6 FP_NORMAL, ... (S. 169-170)
- C11-Standard (ISO/IEC 9899:2011)
- 7.12/6 FP_NORMAL, ... (S. 232)
- C99-Standard (ISO/IEC 9899:1999)
- 7.12/6 FP_NORMAL, ... (S. 213)
[bearbeiten] Siehe auch
| (C99) |
klassifiziert den gegebenen Gleitkommawert (Funktionsmakro) |
| C++ Dokumentation für FP_categories
| |