Namespaces
Variants

FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_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
Arguments and return values
FP_NORMAL FP_SUBNORMAL FP_ZERO FP_INFINITE FP_NAN
(C99) (C99) (C99) (C99) (C99)
Error handling
Fast operation indicators
Definido en el encabezado <math.h>
#define FP_NORMAL    /*implementation defined*/
(desde C99)
#define FP_SUBNORMAL /*implementation defined*/
(desde C99)
#define FP_ZERO      /*implementation defined*/
(desde C99)
#define FP_INFINITE  /*implementation defined*/
(desde C99)
#define FP_NAN       /*implementation defined*/
(desde C99)

Las macros FP_NORMAL , FP_SUBNORMAL , FP_ZERO , FP_INFINITE , FP_NAN representan cada una una categoría distinta de números de punto flotante. Todas se expanden a una expresión constante entera.

Constante Explicación
FP_NORMAL indica que el valor es normal , es decir, no es infinito, subnormal, no es un número o cero
FP_SUBNORMAL indica que el valor es subnormal
FP_ZERO indica que el valor es cero positivo o negativo
FP_INFINITE indica que el valor no es representable por el tipo subyacente (infinito positivo o negativo)
FP_NAN indica que el valor no es un número (NaN)

Ejemplo

#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));
}

Salida:

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

Referencias

  • Estándar C17 (ISO/IEC 9899:2018):
  • 7.12/6 FP_NORMAL, ... (p: 169-170)
  • Estándar C11 (ISO/IEC 9899:2011):
  • 7.12/6 FP_NORMAL, ... (p: 232)
  • Estándar C99 (ISO/IEC 9899:1999):
  • 7.12/6 FP_NORMAL, ... (p: 213)

Véase también

clasifica el valor de punto flotante dado
(macro de función)
Documentación de C++ para FP_categories