C - <float.h>

The C <float.h> header file describes the characteristics of floating types. It contains platform-dependent and implementation-specific floating point values. A floating-point value consist of four parts:

• Sign: It can be either negative or non-negative.
• Base: It is also known as radix of the exponent representation, 2 for binary, 10 for decimal, 16 for hexadecimal, and so on...
• Significand: It is also known as mantissa which is a series of digits of the base. The number of digits in this series is known as precision.
• Exponent: It is also known as characteristic or scale, which represents the offset of the significand.

Based on the above four parts, a floating value can be expressed as follows:

value of floating-point = ± significand x baseexponent

C <float.h> Macro Constants

The below mentioned macros are implementation-specific and defined with the #define directive. The table below shows the different macros in <float.h> header and their minimal or maximal values in all implementations. In all instances it represents the following:

• FLT: refers float
• DBL: refers double
• LDBL: refers long double
• DIG: refers digits
• MAX: refers maximum
• MIN: refers minimum
• MANT: refers mantissa
MacrosDescription
FLT_RADIX Radix (integer base) used by the representation of all three floating-point types (float, double and long double).
Minimum value is 2.
FLT_MANT_DIG
DBL_MANT_DIG
LDBL_MANT_DIG
Number of base FLT_RADIX digits that can be represented without losing precision for float, double and long double respectively.
FLT_DIG
DBL_DIG
LDBL_DIG
Number of decimal digits that can be rounded into a floating-point and back again to the same decimal digits, without loss of precision.
It is defined as AT LEAST 6, 10 and 10 digits for float, double and long double respectively.
FLT_MAX
DBL_MAX
LDBL_MAX
Maximum finite value of float, double and long double respectively.
Minimum value is 1037.
FLT_MIN
DBL_MIN
LDBL_MIN
Minimum finite value of float, double and long double respectively.
Maximum value is 10-37.
FLT_MAX_EXP
DBL_MAX_EXP
LDBL_MAX_EXP
Maximum positive integer such that FLT_RADIX raised by power one less than that integer is a representable finite float, double and long double respectively.
FLT_MIN_EXP
DBL_MIN_EXP
LDBL_MIN_EXP
Minimum negative integer such that FLT_RADIX raised by power one less than that integer is a normalized float, double and long double respectively.
FLT_MAX_10_EXP
DBL_MAX_10_EXP
LDBL_MAX_10_EXP
Maximum positive integer such that 10 raised to that power is a representable finite float, double and long double respectively.
Minimum value is 37.
FLT_MIN_10_EXP
DBL_MIN_10_EXP
LDBL_MIN_10_EXP
Minimum negative integer such that 10 raised to that power is a normalized float, double and long double respectively.
Maximum value is -37.
FLT_EPSILON
DBL_EPSILON
LDBL_EPSILON
Difference between 1.0 and the next representable value for float, double and long double respectively.
Maximum values are 10-5, 10-9 and 10-9 for float, double and long double respectively.
FLT_ROUNDS Default rounding behavior. Possible values are:
• -1 : undetermined
• 0 : rounding toward zero
• 1 : rounding to nearest integer
• 2 : rounding toward positive infinity
• 3 : rounding toward negative infinity
FLT_EVAL_METHOD Specifies the evaluation format of arithmetic operations. Possible values are:
• -1 : undetermined
• 0 : evaluate in the range and precision of the type
• 1 : evaluate float and double as double, and long double as long double
• 2 : evaluate all as long double
• Other negative values indicate an implementation-defined behavior.
DECIMAL_DIG Number of decimal digits that can be rounded into a floating-point type and back again to the same decimal digits, without loss in precision.
FLT_DECIMAL_DIG
DBL_DECIMAL_DIG
LDBL_DECIMAL_DIG
Number of decimal digits that can be rounded into a floating-point and back again to the same decimal digits, without loss of precision.
It is defined as AT LEAST 6, 10 and 10 digits for float, double and long double respectively, or 9 for IEEE float and 17 for IEEE double.
FLT_TRUE_MIN
DBL_TRUE_MIN
LDBL_TRUE_MIN
Minimum positive value of float, double and long double respectively.
FLT_HAS_SUBNORM
DBL_HAS_SUBNORM
LDBL_HAS_SUBNORM
Specifies whether the type supports subnormal (denormal) numbers:
• -1 : indeterminable
• 0 : absent
• 1 : present

Example:

The example below describes the working of macros constant of C <float.h> library.

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

int main (){

printf("FLT_DIG: %i\n", FLT_DIG);
printf("FLT_MAX: %e\n", FLT_MAX);
printf("FLT_MIN: %e\n", FLT_MIN);
printf("FLT_MAX_EXP: %i\n", FLT_MAX_EXP);
printf("FLT_MIN_EXP: %i\n", FLT_MIN_EXP);
printf("FLT_MAX_10_EXP: %i\n", FLT_MAX_10_EXP);
printf("FLT_MIN_10_EXP: %i\n", FLT_MIN_10_EXP);
printf("FLT_EPSILON: %e\n", FLT_EPSILON);
printf("FLT_ROUNDS: %i\n", FLT_ROUNDS);
printf("FLT_EVAL_METHOD: %i\n", FLT_EVAL_METHOD);

return 0;
}

The output of the above code is machine dependent. One of the possible output could be: