BUG: Global-Register Allocation Generates Incorrect ResultsLast reviewed: July 22, 1997Article ID: Q116241 |
1.00 1.50
WINDOWS
kbtool kbbuglist
The information in this article applies to:
SYMPTOMSThe use of the global-register-allocation optimization switch, /Oe, on floating-point intensive code, such as in the sample below, can generate incorrect results.
RESOLUTIONThere are several methods that can be used to work around this problem:
STATUSMicrosoft has confirmed this to be a bug with the C/C++ compiler for MS-DOS, versions 8.0 and 8.0c. We are researching the problem and will post new information here in the Microsoft Knowledge Base as it becomes available. The problem does not occur with the 32-bit C/C++ compiler.
MORE INFORMATIONThe following sample code can be used to demonstrate this problem:
Sample Code
/* Compile options needed: /Oe */ TEST.c
#include <stdio.h> #include <math.h> void junk(void) { } void main(void) { double x, y, x1 = 623.0, x2 = 724.0, y1 = 308.0, y2 = 244.0; double angle1 = 325, angle2 = 265; #ifdef FIX volatile double m1 = -0.70, m2 = 11.43; #else double m1 = -0.70, m2 = 11.43; #endif m1 = tan( (double)angle1 / 180.0 * 3.1415926535 ); m2 = tan( (double)angle2 / 180.0 * 3.1415926535 ); if( fabs( m1 ) > 99999 ) { x = x1; y = m2 * ( x - x2 ) + y2; } else if( fabs( m2 ) > 99999 ) { x = x2; y = m1 * ( x - x1 ) + y1; } else { // Bad optimizations occur in this code // Uncomment this line to fix the problem // junk(); x = ( m1 * x1 - m2 * x2 - y1 + y2 ) / ( m1 - m2 ); y = m1 * ( x - x1 ) + y1; } printf ("x = %f, y = %f\n",x, y); } Output
x = -723.445934, y = 1250.791593 Correct Output
x = 723.445934, y = 237.667000 |
Additional reference words: 1.00 1.50 8.00 8.00c
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |