<cfloat> float.h in C/C++ with Examples

25 Nov, 2019
This header file consists of platform-dependent and implementation specific floating point values. A floating point has four parts.
SignIts value can be either negative or non-negative.
BaseIt is also known as radix of exponent representation which represents different numbers with single number i.e. 2 for binary, 10 for decimal, 16 for hexadecimal, ...
MantissaIt is also known as significand.It is a series of digits of the base. The number of digits in the series is known as precision.
ExponentIt is also known as characteristic is an integer between minimum emin and maximum emax.
Value of floating point = ± precision X baseexponent
Macro constants
Library macros are hardware-specific values for the floating-point types.FLT implies type float, DBL implies double, and LDBL implies long double, DIG implies digits, MANT implies mantissa, EXP implies exponent.
FLT_RADIX: Base for all floating-point typesMinimum value is 2FLT_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.Minimum value is 6DBL_DIG or LDBL_DIG: Number of decimal digits that can be rounded into a floating-point and back without change in the number of decimal digits.Minimum value is 10DECIMAL_DIG: Decimal digits needed to represent floating-point valueNo Minimum valueFLT_MANT_DIG or DBL_MANT_DIG or LDBL_MANT_DIG: Precision of mantissa i.e. the number of digits that conform the significand.No Minimum valueFLT_MIN_EXP or DBL_MIN_EXP or LDBL_MIN_EXP: Minimum negative integer value for the exponent that generates a normalized floating-point number.No Minimum valueFLT_MIN_10_EXP or DBL_MIN_10_EXP or LDBL_MIN_10_EXP: Minimum negative integer value for the exponent of a base-10 expression that would generate a normalized floating-point number.Maximum value is -37FLT_MAX_EXP or DBL_MAX_EXP or LDBL_MAX_EXP: Maximum integer value for the exponent that generates a normalized floating-point number.No Minimum valueFLT_MAX_10_EXP or DBL_MAX_10_EXP or LDBL_MAX_10_EXP: Maximum integer value for the exponent of a base-10 expression that would generate a normalized floating-point number.Minimum value is 37FLT_MAX or DBL_MAX or LDBL_MAX: Maximum finite representable floating-point number.Minimum value is 1037FLT_EPSILON: Difference between 1 and the least value greater than 1 that is representable.Maximum value is 10-5DBL_EPSILON or LDBL_EPSILON: Difference between 1 and the least value greater than 1 that is representable.Maximum value is 10-9FLT_MIN or DBL_MIN or LDBL_MIN: Minimum representable positive floating-point number.Maximum value is 10-37FLT_ROUNDS: Rounds off the floating-point numberDifferent possible values are:-1 : indeterminate
 0 : towards zero
 1 : towards one
 2 : towards positive infinity
 3 : towards negative infinity
FLT_EVAL_METHOD: Rounds off the floating-point numberDifferent possible values are:-1 : undetermined
 0 : evaluate just to 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 and Other 
     negative values indicate an 
     implementation defined behavior.

FLT_RADIX: Base for all floating-point typesMinimum value is 2
Minimum value is 2
FLT_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.Minimum value is 6
Minimum value is 6
DBL_DIG or LDBL_DIG: Number of decimal digits that can be rounded into a floating-point and back without change in the number of decimal digits.Minimum value is 10
Minimum value is 10
DECIMAL_DIG: Decimal digits needed to represent floating-point valueNo Minimum value
No Minimum value
FLT_MANT_DIG or DBL_MANT_DIG or LDBL_MANT_DIG: Precision of mantissa i.e. the number of digits that conform the significand.No Minimum value
No Minimum value
FLT_MIN_EXP or DBL_MIN_EXP or LDBL_MIN_EXP: Minimum negative integer value for the exponent that generates a normalized floating-point number.No Minimum value
No Minimum value
FLT_MIN_10_EXP or DBL_MIN_10_EXP or LDBL_MIN_10_EXP: Minimum negative integer value for the exponent of a base-10 expression that would generate a normalized floating-point number.Maximum value is -37
Maximum value is -37
FLT_MAX_EXP or DBL_MAX_EXP or LDBL_MAX_EXP: Maximum integer value for the exponent that generates a normalized floating-point number.No Minimum value
No Minimum value
FLT_MAX_10_EXP or DBL_MAX_10_EXP or LDBL_MAX_10_EXP: Maximum integer value for the exponent of a base-10 expression that would generate a normalized floating-point number.Minimum value is 37
Minimum value is 37
FLT_MAX or DBL_MAX or LDBL_MAX: Maximum finite representable floating-point number.Minimum value is 1037
Minimum value is 1037
FLT_EPSILON: Difference between 1 and the least value greater than 1 that is representable.Maximum value is 10-5
Maximum value is 10-5
DBL_EPSILON or LDBL_EPSILON: Difference between 1 and the least value greater than 1 that is representable.Maximum value is 10-9
Maximum value is 10-9
FLT_MIN or DBL_MIN or LDBL_MIN: Minimum representable positive floating-point number.Maximum value is 10-37
Maximum value is 10-37
FLT_ROUNDS: Rounds off the floating-point numberDifferent possible values are:-1 : indeterminate
 0 : towards zero
 1 : towards one
 2 : towards positive infinity
 3 : towards negative infinity

-1 : indeterminate
 0 : towards zero
 1 : towards one
 2 : towards positive infinity
 3 : towards negative infinity

FLT_EVAL_METHOD: Rounds off the floating-point numberDifferent possible values are:-1 : undetermined
 0 : evaluate just to 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 and Other 
     negative values indicate an 
     implementation defined behavior.

-1 : undetermined
 0 : evaluate just to 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 and Other 
     negative values indicate an 
     implementation defined behavior.

Below is the program to demonstrate the working of macros constants in cfloat library.
// C++ program to demonstrate working// of macros constants in cfloat library  #include <cfloat>#include <iostream>using namespace std;  int main(){    cout << "FLT_RADIX : "         << FLT_RADIX << endl;    cout << "FLT_DIG : "         << FLT_DIG << endl;    cout << "DECIMAL_DIG : "         << DECIMAL_DIG << endl;    cout << "FLT_MIN_10_EXP : "         << FLT_MIN_10_EXP << endl;    cout << "FLT_MAX_EXP : "         << FLT_MAX_EXP << endl;    cout << "FLT_MAX_10_EXP : "         << FLT_MAX_10_EXP << endl;    cout << "FLT_MAX : "         << FLT_MAX << endl;    cout << "FLT_MIN : "         << FLT_MIN << endl;    return 0;}
FLT_RADIX : 2
FLT_DIG : 6
DECIMAL_DIG : 21
FLT_MIN_10_EXP : -37
FLT_MAX_EXP : 128
FLT_MAX_10_EXP : 38
FLT_MAX : 3.40282e+38
FLT_MIN : 1.17549e-38

Reference: http://www.cplusplus.com/reference/cfloat/
C-Library
CPP-Library
C Language
C++
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.