Andrea Arcangeli wrote:
> I discovered a gcc bug in the -ffloat-store option.
>
> This program:
>
> #include <stdio.h>
>
> int main(void) {
>
> float reale = 1.0f;
> int i = 0;
>
> for (; (reale + 1.0f) != 1.0f; i++) {
> reale=(float)reale/2.0f;
> }
> printf("\ni volte = %d\n",i);
> }
>
> This program must output 24 instead of 64 if compiled with -ffloat-store.
Are you sure? The documentation of -ffloat-store says:
`-ffloat-store'
Do not store floating point variables in registers, and inhibit
other options that might change whether a floating point value is
taken from a register or memory.
The value `reale + 1.0f' wouldn't generally be stored in memory, so
using -ffloat-store wouldn't affect the above program.
If I re-write it as:
#include <stdio.h>
int main(void)
{
float reale = 1.0f;
float oneplus;
int i;
for (i = 0; ; i++)
{
oneplus = 1.0f + reale;
if (oneplus == 1.0f)
break;
printf("%.30f\n", oneplus);
reale=reale/2.0f;
}
printf("i = %d\n",i);
return 0;
}
then it works OK with or without -ffloat-store, so long as
optimisation is disabled. If I enable optimisation, it uses internal
precision regardless of whether -ffloat-store is used.
--
Glynn Clements <[EMAIL PROTECTED]>