01: // intervallo numeri a virgola mobile, macro sizeof()
02: #include <stdio.h>
03: #include <stdlib.h>
04: #include <float.h> // contiene le costanti usate in questo esempio
05:
06: int main(int argc, char** argv) {
07:
08: printf("Storage size for float : %ld \n", sizeof(float)); // sizeof() restituisce quanti byte occupa un tipo di dato
09: printf("FLT_MAX : %g\n", FLT_MAX);
10: printf("FLT_MIN : %g\n", FLT_MIN);
11: printf("Number of decimal digits that can be accurately represented: %d\n", FLT_DIG );
12:
13: printf("\nStorage size for double : %ld \n", sizeof(double));
14: printf("DBL_MAX : %g\n", DBL_MAX);
15: printf("DBL_MIN : %g\n", DBL_MIN);
16: printf("Number of decimal digits that can be accurately represented: %d\n", DBL_DIG );
17:
18: printf("\nStorage size for long double : %ld \n", sizeof(long double));
19: printf("LDBL_MAX : %Lg\n", LDBL_MAX);
20: printf("LDBL_MIN : %Lg\n", LDBL_MIN);
21: printf("Number of decimal digits that can be accurately represented: %d\n", LDBL_DIG );
22:
23: float fl = 1.1f; // 23 bit mantissa
24: double db = 1.1; // 54 bit mantissa
25: long double ldb = 1.1L; // 80 bit mantissa
26:
27: printf("\nPrecision Examples:\n\n");
28: printf("float -> %.30f \t %f\n", fl, fl);
29: printf(" ******\n");
30: printf("double -> %.30lf \t %lf\n", db, db);
31: printf(" ***************\n");
32: printf("long double -> %.30Lf \t %Lf\n", ldb, ldb);
33: printf(" ******************\n");
34:
35:
36: return 0;
37: }
38: /*
39: Storage size for float : 4
40: FLT_MAX : 3.40282e+38
41: FLT_MIN : 1.17549e-38
42: Number of decimal digits that can be accurately represented: 6
43:
44: Storage size for double : 8
45: DBL_MAX : 1.79769e+308
46: DBL_MIN : 2.22507e-308
47: Number of decimal digits that can be accurately represented: 15
48:
49: Storage size for long double : 16
50: LDBL_MAX : 1.18973e+4932
51: LDBL_MIN : 3.3621e-4932
52: Number of decimal digits that can be accurately represented: 18
53:
54: Precision Examples:
55:
56: float -> 1.100000023841857910156250000000 1.100000
57: ******
58: double -> 1.100000000000000088817841970013 1.100000
59: ***************
60: long double -> 1.100000000000000000021684043450 1.100000
61: ******************
62: */
63:
Se avete commenti o osservaƶioni su questa pagina
mandate un messaggio di posta elettronica a bertoƶƶi@ce.unipr.it
mandate un messaggio di posta elettronica a bertoƶƶi@ce.unipr.it