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

This header file consists of platform-dependent and implementation specific floating point values. A floating point has four parts.

  • Sign
    Its value can be either negative or non-negative.
  • Base
    It 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, …
  • Mantissa
    It 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.
  • Exponent
    It 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.

  1. FLT_RADIX: Base for all floating-point types
    Minimum value is 2
  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
  3. 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
  4. DECIMAL_DIG: Decimal digits needed to represent floating-point value
    No Minimum value
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. FLT_MAX or DBL_MAX or LDBL_MAX: Maximum finite representable floating-point number.
    Minimum value is 1037
  11. FLT_EPSILON: Difference between 1 and the least value greater than 1 that is representable.
    Maximum value is 10-5
  12. DBL_EPSILON or LDBL_EPSILON: Difference between 1 and the least value greater than 1 that is representable.
    Maximum value is 10-9
  13. FLT_MIN or DBL_MIN or LDBL_MIN: Minimum representable positive floating-point number.
    Maximum value is 10-37
  14. FLT_ROUNDS: Rounds off the floating-point number
    Different possible values are:



    -1 : indeterminate
     0 : towards zero
     1 : towards one
     2 : towards positive infinity
     3 : towards negative infinity
    
  15. FLT_EVAL_METHOD: Rounds off the floating-point number
    Different 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.
    

Below is the program to demonstrate the working of macros constants in cfloat library.

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output (Machine Dependent):

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/

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.