<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.
- FLT_RADIX: Base for all floating-point types
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
- 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
- DECIMAL_DIG: Decimal digits needed to represent floating-point 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
- 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
- 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
- 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
- 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
- FLT_MAX or DBL_MAX or LDBL_MAX: Maximum finite representable floating-point number.
Minimum value is 1037
- FLT_EPSILON: Difference between 1 and the least value greater than 1 that is representable.
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
- FLT_MIN or DBL_MIN or LDBL_MIN: Minimum representable positive floating-point number.
Maximum value is 10-37
- 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
- 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.
// 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; } |
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/
Contact Us