cfloat header in C++ with examples
Hello Students, today we are going to learn about cfloat header file in C++.
cfloat header file present in C++
<cfloat.h> file is a platform-dependent and has the capability of implementing some specific floating-point values.
A floating number has
Sign: Its value can be either positive or negative.
Base: It is the radix of exponential representation i.e. 2 for binary, 8 for octal, 10 for decimal, 16 for hexadecimal, …
Exponent: It is known as a character in an integer between the minimum and the maximum exponential value.
Implementing Macro Constants present in cfloat header file
- FLT implies the type of float.
- DIG implies digits
- EXP implies exponent.
After that, the basic functions we use here are,
- FLT_RADIX: Base for all floating-point types.
- FLT_DIG: It should be turned into a floating-point and come back to the same decimal digit again.
- DECIMAL_DIG: we use this for representing floating values. There is no minimum value.
- FLT_MIN_10_EXP: It is the minimum negative integer value of exponential base 10.
- FLT_MAX_EXP: The maximum value of the exponent
- FLT_MAX_10_EXP: It is the maximum integer value of exponential base 10.
- FLT_MAX: It represents the ultimate floating-point value.
- FLT_MIN: It is the smallest positive floating value.
Code
Below is the given C++ code for cfloat header file:
//C++ program to represent macro constants in cfloat library #include <cfloat> #include <iostream> #define DECIMAL_DIG 20 using namespace std; int main() { cout << "FLT_RADIX value : "<< FLT_RADIX << endl; cout << "FLT_DIG value : "<< FLT_DIG << endl; cout << "DECIMAL_DIG value : "<<DECIMAL_DIG << endl; cout << "FLT_MIN_10_EXP value : "<< FLT_MIN_10_EXP << endl; cout << "FLT_MAX_EXP value : "<< FLT_MAX_EXP << endl; cout << "FLT_MAX_10_EXP value : "<< FLT_MAX_10_EXP << endl; cout << "FLT_MAX value : "<< FLT_MAX << endl; cout << "FLT_MIN value : "<< FLT_MIN << endl; return 0; }
After running the above program, we can get the output result:
FLT_RADIX : 2 FLT_DIG : 6 DECIMAL_DIG : 20 FLT_MIN_10_EXP : -37 FLT_MAX_EXP : 128 FLT_MAX_10_EXP : 38 FLT_MAX : 3.40282e+038 FLT_MIN : 1.17549e-038 (The above mentioned output is machine dependent)
Leave a Reply