floating point - Range of magnitude for float in c programming language? -


in c programming language book dennis ritchie, mentioned "a float number typically 32-bit quantity, @ least 6 significant digits , magnitude between 10^-38 , 10^+38."

how possible since have 32-bits? shouldn't top limit 2^32? tried printing out float looping , multiplying float 10, 38 times , output 100000006944061730000000000000000000000.000000 . has keep track of sign , how storing in 32-bits?

see single-precision floating-point format details typical c float.

range of magnitude float in c programming language?

#include <float.h> printf("float magnitude range %e %e\n", flt_min, flt_max); // typical result // float magnitude range 1.175494e-38 3.402823e+38 

how possible since have 32-bits?

typical float indeed store 232 different values. yet not distributed linearly logarithmically in linear groups.

223 different values in range [2-126 2-127)
...
223 different values in range [0.5 1.0)
223 different values in range [1.0 2.0)
223 different values in range [2.0 4.0)
...
223 different values in range [2127 2128)

and negative counter parts.
+/- zeros, small sub-normal numbers, +/- infinity , not-a-number

it has keep track of sign , how storing in 32-bits?

 1 bit sign  8 bits binary exponent 23 bits significant (with msbit implied 1) -- 32 bits 

when printing float, 6 or (flt_dig, flt_decimal_dig) significant digits important.

printf("%.*e\n", flt_dig-1, flt_true_min); printf("%.*e\n", flt_dig-1, flt_min); printf("%.*e\n", flt_dig-1, acos(-1)); printf("%.*e\n", flt_decimal_dig - 1, nextafterf(flt_max, 0.0)); printf("%.*e\n", flt_decimal_dig - 1, flt_max); 

output

1.40130e-45    // min sub-normal 1.17549e-38    // min normal 3.14159e+00    // pi 3.40282326e+38 // number before max 3.40282347e+38 // max 

Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -