PATCH: Visual C++ sin(), cos(), and tan() Incorrect w/ 287

ID: Q126882


The information in this article applies to:


SYMPTOMS

Calls to the sin(), cos(), or tan() in a program built with the Visual C++ versions listed at the beginning of this article return incorrect results.


CAUSE

This is caused by a bug in the Visual C++ run-time (CRT) functions. The functions have a problem with 287 synchronization on 80286 systems with 80287 coprocessors. The timing problem does not affect programs running on an 80386 with an 80387 coprocessor, on an 80486, or on a Pentium processor.


RESOLUTION

You can get a patch (VC287P.EXE) to fix a bug that occurs with the sin(), cos(), and tan() run-time functions. These functions return incorrect values when a program built with Visual C++ is run on a computer that has both an 80286 processor and an 80287 math coprocessor.

The following file is available for download from the Microsoft Software Library:

~ Vc287p.exe

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

Q119591 How to Obtain Microsoft Support Files from Online Services


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was corrected in the patch announced in this article.


MORE INFORMATION

Please note that this patch is a partially tested fix for this problem. No problems have been detected with it, however it has not gone through a full product test cycle. Microsoft makes no guarantees for its useability or functionality. See the LEGAL.TXT included with the patch for more details.

The patch also contains a README.TXT with installation details and the information in this article.

Sample Code to Reproduce Problem


   /* Compile options needed: None
   */ 
   #include <math.h>
   #include <stdio.h>
   #include <stdlib.h>

   void main(void)
   {
      double x;

      x=1.0;
      printf( "cos(x) = %lf, sin(x) = %lf, tan(x) = %lf, x = %lf\n",
              cos(x), sin(x), tan(x), x );
   } 

Results

The following correct output was produced on a 286/287 with NO87=1:

   cos(x) = 0.540302, sin(x) = 0.841471, tan(x) = 1.557408, x = 1.000000 
The following incorrect output was produced on a 286/287 with NO87 not set:

   cos(x) = 1.000000, sin(x) = 2.000000, tan(x) = 0.000000, x = 1.000000 

Additional query words:


Keywords          : kbfile kbhw kbprg kbCRT kbVC 
Version           : 1.00 1.50 1.51 1.52
Platform          : WINDOWS 
Issue type        : 

Last Reviewed: July 27, 1999