float.h in C

The header file named float.h of Library C contains a set of diverse constants (platform dependent) related to floating point real number values.

float.h in C

The header file named float.h of Library C contains a set of diverse constants (platform dependent) related to floating point real number values. These constants are proposed by ANSI C. Before understanding these constants, you need to know the floating-point real number of 4 components:

Composition Description (+/-) b Representation of base: binary is 2, decimal is 10, hexadecimal is 16, . e exponent (exponent), an integer between e min and e max p Meaning decimal number (Precision)

Based on the above 4 components, a floating point number will have its value expressed as follows:

 s ố th ự c d ấ u ch ấ m độ ng = ( S ) p x b e ho ặ c s ố th ự c d ấ u ch ấ m độ ng = (+/-) precision x base exponent 

Macros are defined in float.h

The following values ​​are separate implementers and are defined with #define directives, but these values ​​cannot be lowercase. Note that all FLT references to float type, DBL refers to double and LDBL refers to long double.

Macro Description FLT_ROUNDS Defining the rounding mode allows the addition of floating point numbers and it can have any of the following values:
-1 - Unknown
0 - Round to 0
1 - Rounding to the nearest value
2 - Towards positive infinity
3 - Towards infinity negative FLT_RADIX 2 Definition represents the radix of the exponent. Base-2 is binary, base-10 is a decimal system .

FLT_MANT_DIG

DBL_MANT_DIG

LDBL_MANT_DIG

These macros define the number of digits to represent the real number (in FLT_RADIX base)

FLT_DIG 6

DBL_DIG 10

LDBL_DIG 10

These macros determine the maximum number of decimal places (base-10) that can be represented without changing after rounding.

FLT_MIN_EXP

DBL_MIN_EXP

LDBL_MIN_EXP

These macros determine the smallest vowel value for exponent in FLT_RADIX radix

FLT_MIN_10_EXP -37

DBL_MIN_10_EXP -37

LDBL_MIN_10_EXP -37

These macros define the smallest vowel value for an exponent in base 10

FLT_MAX_EXP

DBL_MAX_EXP

LDBL_MAX_EXP

These macros define the maximum integer value for an exponent in FLT_RADIX base

FLT_MAX_10_EXP +37

DBL_MAX_10_EXP +37

LDBL_MAX_10_EXP +37

These macros define the maximum integer value for an exponent in base 10

FLT_MAX 1E + 37

DBL_MAX 1E + 37

LDBL_MAX 1E + 37

These macros determine the largest floating point real number value

FLT_EPSILON 1E-5

DBL_EPSILON 1E-9

LDBL_EPSILON 1E-9

These macros define the least significant digit that can be represented

FLT_MIN 1E-37

DBL_MIN 1E-37

LDBL_MIN 1E-37

These macros define the smallest floating point real number values

For example

The following program C illustrates the usage of some constants defined in float.h.

 #include #include int main () { printf ( "Gia tri max cua mot so thuc = %.10en" , FLT_MAX ); printf ( "Gia tri min cua mot so thuc = %.10en" , FLT_MIN ); printf ( "So ky so de bieu dien mot so = %.10en" , FLT_MANT_DIG ); } 

Compiling and running the above C program will result:

float.h in C Picture 1float.h in C Picture 1

According to Tutorialspoint

Previous article: errno.h in C

Next lesson: limits.h in C

4 ★ | 3 Vote