Bug 000104
When Created: 08/05/1996 16:43:03
Against DJGPP version: 2.00
By whom: oursema6@etud.dauphine.fr
Abstract: incrementation of a float
# include <stdlib.h>
# include <stdio.h>
# include <time.h>
void main() {
float f=0.0;
double d=0.0;
unsigned long l = 0;
time_t start = clock();
while ((clock()-start) < 3000) {
f++;
d++;
l++;
}
fprintf (stdout,"f(%f) d(%f) l(%ld)\n",f,d,l);
}
by using this programme for about 30s en a P75 (or even less)
we see that the float f has a limit of 16777216.
Is this realy a bug?
Thx
Maximilien
Note added: 08/05/1996 17:09:31
By whom: terra@diku.dk (Morten Welinder)
Simpler than that.
Floats have, I think, 24 bit precision. 16... is about 2^24
so adding one does not change the number due to loss of
precision.
I behaviour on this hp900s700 running hpux, btw, except that
clock() is so slow being a system call that I have to let it
run for ~300s.
Note added: 08/06/1996 05:15:14
By whom: oursema6@etud.dauphine.fr
thank for answring.
Why do you say that a float has a 24bit precision?
Because when I do a sizeof(float) I get 4 as an answer
and not 3. Or is it because a float use 24bit of
precision and 8bit of mantise. Anyway, it is said that
a float has a range of 3.4E-38 and 3.4E38, so it should
be able to an incrementation, isn't??
M
Note added: 08/06/1996 17:09:10
By whom: terra@diku.dk (Morten Welinder)
sizeof (int) == 4, right.
From memory, this is 24 bits mantissa, 7 bits exponent, and one
bit for sign (for mantissa).
It is true that a float can hold values up to 10^38 or something
like that. But -- and this is the catch -- not every number (and
in particular not every integer) has a precise representation as
a float.
Once you get above 2^24 there will be "holes" between the
numbers: 2^24 can be represented, 2+2^24 can be too, but
1+2^24 cannot. This means that 1+2^24 must be rounded to
something that can be represented. If it is rounded to
2^24 then adding one didn't make any difference. If it is
rounded to 2+2^24 then you actually ended up adding 2!
In summary: you are seeing a rounding effect.
Closed on 09/13/1996 22:23:32: not a bug
By whom: dj@delorie.com