This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Re: [www-patch] bugs.html rewrite, part 2: revamp floating point section


Re:

+<p>On some architectures calculations inside the floating point unit (FPU)
+are done with higher precision than memory operations like storing floating
+point numbers (e.g., a <code>double</code> has 80 bits in the FPU on x86,
+but only 64 bits in memory). Thus, writing data to memory involves rounding!
+That's why the following C program might print <code>"Uh oh!"</code>.</p>
+<blockquote><pre>
+int main()
+{
+ double x=sqrt(2.0);
+ volatile double y=x;
+ if (x!=y) printf("Uh oh!\n");
+ return 0;
+}
+</pre></blockquote>
+
+<p>Again, this is not a bug in the compiler, but a result of rounding
+(in conjunction with the excess precision of the FPU).</p>

I would claim that this *is* a bug in the compiler, but it's one that's extremely unlikely to be fixed in the foreseeable future, and we've rehashed this all before.


Why not try

+<blockquote><pre>
+int main()
+{
+  volatile double y=sqrt(2.0);
+  if (sqrt(2.0)!=y) printf("Uh oh!\n");
+  return 0;
+}
+</pre></blockquote>

Then I think we would both agree that if the programmer didn't expect "Uh oh!" to be printed, then their expectations need to be realigned on the x86.


Brad


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