>>> How many float values can be represented
>>> in the range of 0f through 1f inclusive?
[quoted text clipped - 5 lines]
>
> It's not quite correct.
Perhaps you could identify a bit pattern in that range that does not
represent a floating point number, or a bit pattern outside the range I
gave that corresponds to a floating point number in 0f through 1f.
> So, (don't forget normalization, which actually prevents such things,
> but the DO exist in memory) we need to know what are
> exponent (2*e) and fraction (1.+ .f) in our implementation.
> In Java float is 32 bites.
> So, e has 8 bits and f has 23.
Normalized floats in IEEE754 do not store the leading 1 bit. However,
the positive denomalized floats, bit patterns 0x00000001 through
0x007fffff, are also in the specified range.
> And last number - don't forget +0 and -0 which are two different
> representation of one number 0. So, we have +1 for -0 in total
> calculation.
To the limited extent that they are distinct values, I would not think
of -0 as being in the range. -0 seems to me more like a placeholder for
negative values that underflow to zero. On the other hand, if they are
the same value then including -0 makes no difference in the count of
float values.
Patricia
Lew - 22 Mar 2008 21:34 GMT
> Perhaps you could identify a bit pattern in that range that does not
> represent a floating point number, or a bit pattern outside the range I
> gave that corresponds to a floating point number in 0f through 1f.
Alex.From.Ohio.Java@gmail.com wrote:
>> So, (don't forget normalization, which actually prevents such things,
>> but the DO exist in memory) we need to know what are
>> exponent (2*e) and fraction (1.+ .f) in our implementation.
>> In Java float is 32 bites.
>> So, e has 8 bits and f has 23.
So there are 31 bits, plus the sign bit.
Alex.From.Ohio.Java@gmail.com wrote:
>> Anything which is less then half of 2 is 1. So, All e<0 (127) are
>> between 0 and 1.
>> That's 2**23 * 127
2 ** 23 * (2 ** 7 - 1 )
= 2 ** 30 - 2 ** 23
Your calculations already are on the order of 2 ** 30.
> Normalized floats in IEEE754 do not store the leading 1 bit. However,
> the positive denomalized floats, bit patterns 0x00000001 through
> 0x007fffff, are also in the specified range.

Signature
Lew
Alex Kizub - 23 Mar 2008 14:09 GMT
> > Perhaps you could identify a bit pattern in that range that does not
> > represent a floating point number, or a bit pattern outside the range I
[quoted text clipped - 24 lines]
> --
> Lew
OK, OK.
Little tiny hint doesn't work.
Let's use brutal force:
float f;
long i=0, c=0;
for(; (i&0x100000000L)==0; i++){
f=Float.intBitsToFloat((int)i);
if (f<=2f&&f>=0f){
c++;
}
}
System.out.println(c+" "+i);
System.out.println(Math.pow(2, 30));
and output is:
1073741826 4294967296
1.073741824E9
As you can see float range from 0 to 1 inclusively is 2**30 + 2
(which are -0 and 1).
Sincerely, Alex.
http://www.myjavaserver.com/~alexfromohio/
Patricia Shanahan - 23 Mar 2008 14:53 GMT
>>> Perhaps you could identify a bit pattern in that range that does not
>>> represent a floating point number, or a bit pattern outside the range I
[quoted text clipped - 31 lines]
> f=Float.intBitsToFloat((int)i);
> if (f<=2f&&f>=0f){
I don't understand this test. Why "f<=2f" rather than "f<=1f"? 1.5f is
exactly representable and is less than 2f, but is not in the required range.
> c++;
> }
[quoted text clipped - 12 lines]
> Sincerely, Alex.
> http://www.myjavaserver.com/~alexfromohio/
Alex.From.Ohio.Java@gmail.com - 23 Mar 2008 15:35 GMT
> I don't understand this test. Why "f<=2f" rather than "f<=1f"? 1.5f is
> exactly representable and is less than 2f, but is not in the required range.
> > 1073741826 4294967296
> > 1.073741824E9
You are right. I played with it a little and forgot to change back.
1065353218 4294967296
1.073741824E9
Alex.
Patricia Shanahan - 23 Mar 2008 16:04 GMT
>> I don't understand this test. Why "f<=2f" rather than "f<=1f"? 1.5f is
>> exactly representable and is less than 2f, but is not in the required range.
[quoted text clipped - 7 lines]
>
> Alex.
This differs by one from 1065353217, the result of my original
suggestion: "Each bit pattern in the range Float.floatToIntBits(0f)
through Float.floatToIntBits(1f) corresponds to a float value in the
specified range.".
The difference is a matter of question interpretation. Should zero be
counted once, because it is one value, equal to itself, or twice because
it has two representations that behave differently in some ways?
Patricia