Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

<float.h> — floating-point type characteristics

The <float.h> header describes the precision, range, and properties of float, double, and long double. Use its macros instead of assuming a hardware format; selecting a C23 compiler flag alone does not attest library support or the production runtime.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <float.h>

Include #include <float.h>. Below, T means each prefix FLT, DBL, LDBL, for float, double, long double respectively; for example, T_MIN covers FLT_MIN, DBL_MIN, LDBL_MIN. Values depend on the implementation, not an assumed hardware format.

FLT_RADIX is the radix b. T_MANT_DIG counts significand digits in base b; T_DIG describes preservation of digits for decimal → type → decimal conversion, whereas T_DECIMAL_DIG describes type → decimal → type conversion, with appropriate rounding. Obsolescent DECIMAL_DIG covers the widest supported types and IEC 60559 encodings. T_MIN_EXP is the smallest e for which b^(e-1) is normalized; T_MAX_EXP is the largest e for which it is finite and representable. T_MIN_10_EXP and T_MAX_10_EXP give corresponding bounds for 10^e: the normalized range at the lower end, the finite range at the upper end.

T_MIN is the smallest positive normalized number, not the most negative number; T_TRUE_MIN is the smallest positive representable number. T_MAX is the largest finite number, whereas T_NORM_MAX is the largest normalized number. T_EPSILON is the gap from 1 to the next greater normalized number, not a universal comparison tolerance. Obsolescent T_HAS_SUBNORM: -1 indeterminable, 0 absent, 1 subnormals supported. T_IS_IEC_60559: 0 means the precision and exponent range do not match any IEC 60559 format; 1 means they match an IEC 60559 format but the type does not use an IEC 60559 encoding; 2 means they match an IEC 60559 format and the type also uses an IEC 60559 encoding. This macro alone does not guarantee conformance to Annex F. FLT_SNAN, DBL_SNAN, and LDBL_SNAN expand to expressions of type float, double, and long double, respectively, each with a signaling NaN as its value. Each macro is defined only if its corresponding type supports signaling NaNs; check with #ifdef.

FLT_ROUNDS describes addition rounding: -1 indeterminable, 0 toward zero, 1 to nearest, 2 toward positive infinity, 3 toward negative infinity, 4 nearest with ties away from zero; other values are implementation-defined. For 1, ties-to-even is guaranteed by the Annex F binding to IEC 60559, not by FLT_ROUNDS alone. It can change at runtime. FLT_EVAL_METHOD: -1 indeterminable, 0 type's own format, 1 evaluate float and double in double, 2 evaluate all in long double; with 1, long double stays unchanged. Other negative values are implementation-defined. The example checks relationships instead of specific formats.

Reference identifiers covered by this entry: FLT_MANT_DIG, FLT_DECIMAL_DIG, FLT_DIG, FLT_MIN_EXP, FLT_MIN_10_EXP, FLT_MAX_EXP, FLT_MAX_10_EXP, FLT_MAX, FLT_EPSILON, FLT_TRUE_MIN, FLT_HAS_SUBNORM, FLT_IS_IEC_60559, FLT_NORM_MAX, FLT_SNAN, DBL_MANT_DIG, DBL_DECIMAL_DIG, DBL_DIG, DBL_MIN_EXP, DBL_MIN_10_EXP, DBL_MAX_EXP, DBL_MAX_10_EXP, DBL_MAX, DBL_EPSILON, DBL_TRUE_MIN, DBL_HAS_SUBNORM, DBL_IS_IEC_60559, DBL_NORM_MAX, DBL_SNAN, LDBL_MANT_DIG, LDBL_DECIMAL_DIG, LDBL_DIG, LDBL_MIN_EXP, LDBL_MIN_10_EXP, LDBL_MAX_EXP, LDBL_MAX_10_EXP, LDBL_MAX, LDBL_EPSILON, LDBL_TRUE_MIN, LDBL_HAS_SUBNORM, LDBL_IS_IEC_60559, LDBL_NORM_MAX, LDBL_SNAN.

Examples

#include <float.h>
#include <stdio.h>

int main(void)
{
    printf("radix >= 2: %d\n", FLT_RADIX >= 2);
    printf("positive minimum: %d\n", DBL_MIN > 0.0);
    printf("true minimum <= minimum: %d\n", DBL_TRUE_MIN <= DBL_MIN);
    printf("maximum >= minimum: %d\n", LDBL_MAX >= LDBL_MIN);
    return 0;
}

Result

radix >= 2: 1
positive minimum: 1
true minimum <= minimum: 1
maximum >= minimum: 1

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources