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] |
+<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>
+<blockquote><pre> +int main() +{ + volatile double y=sqrt(2.0); + if (sqrt(2.0)!=y) printf("Uh oh!\n"); + return 0; +} +</pre></blockquote>
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |