Thursday, June 16, 2011

Implementation-defined Floating-Point Limits

13.  <float.h>  Implementation-defined Floating-Point Limits

The names in the following, a subset of <float.h>, are constants related to floating-point arithmetic.

FLT_DIG
precision in decimal digits for float
FLT_EPSILON
smallest number x of float such that 1.0+x != 1.0
FLT_MAX
maximum value of float
FLT_MIN
minimum normalized value of float
DBL_DIG
precision in decimal digits for double
DBL_EPSILON
smallest number x of double such that 1.0+x != 1.0
DBL_MAX
maximum value of double
DBL_MIN
minimum normalized value of double



 Example Codes
13.       float.h
l float.c
#include <stdio.h>
#include <float.h>
void main(void) {
    printf("%d\n", FLT_DIG);       // 6
    printf("%G\n", FLT_EPSILON);   // 1.19209E-007
    printf("%G\n", FLT_MAX);       // 3.40282E+038
    printf("%G\n", FLT_MIN);       // 1.17549E-038

    printf("%d\n", DBL_DIG);       // 15
    printf("%G\n", DBL_EPSILON);   // 2.22045E-016
    printf("%G\n", DBL_MAX);       // 1.79769E+308
    printf("%G\n", DBL_MIN);       // 2.22507E-308
}

No comments: