In message <41b6a942$0$25784$(E-Mail Removed)>

Johnathan Doe <No-spam-here-johnathan_doe@!!!NOSPAMTHANKS!!!fastmail.com.au> wrote:

> I can google search to find the range of values that can be represented

> in a float by reading up on the IEEE std, but is that the same as how

> many distinct values that can go in a float type?

>

> For instance, floats can distinguish 0.000001 and 0.000002. If I

> started with 0.000001 and kept adding 0.000001 until I hit some maximum

> value (FLT_MAX?) and kept a counter of how many times I added 0.000001,

> would I have a count of how many distinct values can go in a float? And

> would that be the same thing as FLT_MAX - FLT_MIN?
As an additional comment to the other answers you've received, C99 adds

a couple of functions nextafter() and nexttoward() that can be used to

enumerate distinct floating values. This example would count the number of

distinct finite float values:

float f = -FLT_MAX;

long long count = 1;

do

{

f = nextafterf(f, FLT_MAX);

count++;

}

while (f != FLT_MAX);

Anyway, roughly speaking, an IEEE 32-bit single number can hold 2^32

different values, as there are 2^32 different bit patterns for the number.

But more specifically these break down as:

2 zeros (exponent=mantissa=0)

2 infinities (exponent=max, mantissa=0)

16,777,214 NaNs (exponent=max, mantissa<>0)

16,777,214 subnormal numbers (exponent=0, mantissa<>0)

4,261,412,864 normal numbers (0<exponent<max)

The count loop above would count the normals, subnormals and one of the

zeros, so should give 4,278,190,079.

In IEEE, all subnormal and normal numbers are distinct - it's an efficient

representation in that respect. The only "duplicate" coding is +/-0, and that

has its uses in certain infinitesimal convergence calculations - it preserves

the information of which side a cut was approached.

--

Kevin Bracey, Principal Software Engineer

Tematic Ltd Tel: +44 (0) 1223 503464

182-190 Newmarket Road Fax: +44 (0) 1728 727430

Cambridge, CB5 8HE, United Kingdom WWW:

http://www.tematic.com/