FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN
From cppreference.net
C++
Numerics library
| Common mathematical functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical special functions (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical constants (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic linear algebra algorithms (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Data-parallel types (SIMD) (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Floating-point environment (C++11) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Complex numbers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric array (
valarray
)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pseudo-random number generation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bit manipulation (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Saturation arithmetic (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Factor operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Interpolations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Generic numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C-style checked integer arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Common mathematical functions
| Nearest integer floating point operations | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Floating point manipulation functions | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Classification and comparison | |||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||
| Types | |||||||||||||||||||||||||||||||||||||||||
| Macro constants | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
Défini dans l'en-tête
<cmath>
|
||
|
#define FP_NORMAL /* implementation defined */
|
(depuis C++11) | |
|
#define FP_SUBNORMAL /* implementation defined */
|
(depuis C++11) | |
|
#define FP_ZERO /* implementation defined */
|
(depuis C++11) | |
|
#define FP_INFINITE /* implementation defined */
|
(depuis C++11) | |
|
#define FP_NAN /* implementation defined */
|
(depuis C++11) | |
Les macros
FP_NORMAL
,
FP_SUBNORMAL
,
FP_ZERO
,
FP_INFINITE
,
FP_NAN
représentent chacune une catégorie distincte de nombres à virgule flottante. Elles se développent toutes en une expression constante entière.
| Constante | Explication |
FP_NORMAL
|
indique que la valeur est normale , c'est-à-dire ni infinie, ni sous-normale, ni NaN, ni zéro |
FP_SUBNORMAL
|
indique que la valeur est sous-normale |
FP_ZERO
|
indique que la valeur est zéro positif ou négatif |
FP_INFINITE
|
indique que la valeur n'est pas représentable par le type sous-jacent (infini positif ou négatif) |
FP_NAN
|
indique que la valeur est NaN (Not-a-Number) |
Exemple
Exécuter ce code
#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'; }
Sortie :
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
Voir aussi
|
(C++11)
|
catégorise la valeur flottante donnée
(fonction) |
|
Documentation C
pour
FP_categories
|
|