Microsoft KB Archive/178527

= PRB: VB5 SP2 and SP3 Give Incorrect Floating Point Results =

Article ID: 178527

Article Last Modified on 12/10/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Control Creation Edition
 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition

-



This article was previously published under Q178527



SYMPTOMS
Some calculations yield differing results depending on the prior state of the floating point processor.



RESOLUTION
Run a simple calculation, such as D = Int(D), to reset the floating point control registers prior to doing floating point calculations. Note that you may have to do this prior to each calculation sequence, depending on what external calls are made between calculation sequences.



STATUS
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Behavior
 Install Visual Basic 5.0 (without Visual Studio 97 Service Packs 2 or 3) on a clean machine.  Make a project with two CommandButton and the following code: Private Sub Command1_Click Dim K0 As Double, K1 As Double, K2 As Double, N As Double K0 = 0.029204 K1 = -1.0508 K2 = -0.34226 N = 0# Do While N <= 2.75 N = N + 0.02 Loop MsgBox -(K1 + 2# * K2 * N) * Exp(K0 + K1 * N + K2 * N ^ 2) - 0.012 End Sub

Private Sub Command2_Click Dim D As Double D = Int(D) End Sub  Run the program in the IDE and click the CommandButtons in the following order:

Command1

Command2

Command1

The result of the calculation in each case is: 2.80181002613759E-04. Install Visual Basic 5.0 with the Visual Studio 97 SP2 or SP3, and rerun the program. Note that the result of the calculation is different:

 Prior to clicking Command2: 2.80181002613761E-04 After clicking Command2: 2.80181002613759E-04</li></ol> </li></ol>