This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gcc 2.95.2 -O0 bug (double/long double)


Gernot Schreib <schreib@stoch.fmi.uni-passau.de> writes:

[snip]
> Program "dbl_if_test":
> #include <stdio.h>
> 
> int main()
> {
>   double x1=1.0,x2=7.0,
>     max=x1/x2;

Converting 1/7 into binary results in a non-terminating fraction. This
  means it is impossible for a computer to represent 1/7 as an IEEE
  floating point value. 

Furthermore, it means that if 1/7 is approximated at two different
  levels of precision, the two approximations will be unequal.

> 
>   if (x1/x2<=max) {

The C standard allows x1/x2 to be calculated with greater precision
  than that used to store max.

For x86, with -O0, x1/x2 is calculated with 80 bits of precision, but
  max is only stored with 64 bits of precision. So x1/x2 is greater
  than max.

(The x86 FPU has 80 bit registers, but the x86 C ABI specifies
  that 'double' is 64 bits wide when stored in memory. max is stored
  in memory, but the result of x1/x2 is stored in a register, and the
  compare is a register-to-memory compare.)

(with -O1 and up, max, x1, x2, the division, the compare, and the if
  are all calculated at compile time and optimized out - only the call
  to printf() remains.)

>     printf("if-cond = 1\n");
>   }
>   else {
>     printf("if-cond = 0\n");
>   }
> 
>   return 0;
> }
> 
> I considere this as a bug:

It is not a bug, but thank you for trying.

[snip]

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]