BUG: Division of Long Doubles May Generate Incorrect Code

Last reviewed: July 22, 1997
Article ID: Q130731
1.00 1.50 1.51 1.52 WINDOWS kbtool kbbuglist

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE) included with Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, 1.52

SYMPTOMS

Dividing a long double value by a constant may generate incorrect code when the application is built by using the fast compiler.

CAUSE

The fast compiler may generate code that does not load long double constants correctly. This results in errors in floating-point calculations. The sample code below reproduces the problem. Note that the GetRow function is not called, but the code contributes to the problem. This is because of the long doubles that are being initialized in the function.

RESOLUTION

Use the optimizing compiler. To specify this from within the Visual Workbench, choose Project from the Options menu, and then select Compiler. Set the Category to Code Generation and change the Code Generator box to Optimizing. The command line option is /f-.

The optimizing compiler is used by default when building a release version of an application in the Visual Workbench and when using /O compiler options other than /Od.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Sample Code to Reproduce Problem

/* Compile options needed: none
*/

#include <float.h>
#include <stdio.h>

void GetRow() {
     long double a = LDBL_MAX;
     long double b = LDBL_MAX;
     long double c = LDBL_MAX;
     long double d = LDBL_MAX;
     long double e = LDBL_MAX;
     long double f = LDBL_MAX;
     long double g = LDBL_MAX;
}

void main(void) {
     long double var1;
     long double var2 = 0.0f;
     long double var3 = 0.705309f;
     var1 = (long double) (  ( var2 + var3) /  2.0 );
     printf("Should print out 0.325654:\n %Lf\n", var1);
}


Additional reference words: 1.00 1.50 1.51 1.52 8.00 8.00c
KBCategory: kbtool kbbuglist
KBSubcategory: CLIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.