Namespaces
Variants

FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN

From cppreference.net
Common mathematical functions
Nearest integer floating point operations
(C++11)
(C++11)
(C++11) (C++11) (C++11)
Floating point manipulation functions
(C++11) (C++11)
(C++11)
(C++11)
Classification and comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Types
(C++11)
(C++11)
(C++11)
Macro constants
Classification
FP_NORMAL FP_SUBNORMAL FP_ZERO FP_INFINITE FP_NAN
(C++11) (C++11) (C++11) (C++11) (C++11)


Definiert im Header <cmath>
#define FP_NORMAL    /* implementation defined */
(seit C++11)
#define FP_SUBNORMAL /* implementation defined */
(seit C++11)
#define FP_ZERO      /* implementation defined */
(seit C++11)
#define FP_INFINITE  /* implementation defined */
(seit C++11)
#define FP_NAN       /* implementation defined */
(seit C++11)

Die FP_NORMAL -, FP_SUBNORMAL -, FP_ZERO -, FP_INFINITE - und FP_NAN -Makros 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 normal ist, d.h. nicht unendlich, subnormal, keine Zahl (NaN) oder null
FP_SUBNORMAL zeigt an, dass der Wert subnormal ist
FP_ZERO zeigt an, dass der Wert positive oder negative null ist
FP_INFINITE zeigt an, dass der Wert nicht durch den zugrundeliegenden Typ darstellbar ist (positive oder negative Unendlichkeit)
FP_NAN zeigt an, dass der Wert keine Zahl (NaN) ist

Beispiel

#include <cfloat>
#include <cmath>
#include <iostream>
auto show_classification(double x)
{
    switch (std::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()
{
    std::cout << "1.0/0.0 is " << show_classification(1 / 0.0) << '\n'
              << "0.0/0.0 is " << show_classification(0.0 / 0.0) << '\n'
              << "DBL_MIN/2 is " << show_classification(DBL_MIN / 2) << '\n'
              << "-0.0 is " << show_classification(-0.0) << '\n'
              << "1.0 is " << show_classification(1.0) << '\n';
}

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

Siehe auch

(C++11)
kategorisiert den angegebenen Gleitkommawert
(Funktion)
C-Dokumentation für FP_categories