c - strange results of simple floating point operations - bad FPU internal state? -


I have a software project in which I sometimes get weird results from small, simple floating point operations. I think I've missed something, and want some tips about debugging the following problems:

(Compiled using MS VC 6.0, version of Microsoft C compiler is 12) < / P>

The first inconsistency:

  Extension double time, timestamp, timestamp; // History rules have been updated somewhere else; timer_evaluation_function () {if ((time-time group)> = time-time) {timestamp + = time-time; Timer_controlled_code (); } {....}  

For some reason, timer evaluation failed and timed code was not executed. In Debugger, there was no problem in seeing that the position of the trigger was really true, but the FPU refused to find positive results. The following code segment did not have any problems, although it used to display the same operation. The problem was overcome by putting a bogus assessment that could be allowed to fail.

I'm assessing the FPU status, is corrupted by the actions taken before, and there are some compiler flags that will help?

Second Incompatibility:

  Double Key, KP = 1.0, Ti = 0.02; Void timed_code () {K = (kP * (float) 2000) / ((float) 2000 - 2.0 f * ti * 1a6) {....}  

Results # Ind, though debugger evaluates the equation of approximately 0.05. # Ind value is shown in the FIP stack when 2.0F value is loaded using Freed instructions in FFU. The previous instruction loads the integer value 2000 as a double float using the field instruction. Once the #indle value is lost in the FPU stack, but once again Debugger has no problem evaluating the formula. Later, these operations return expected results.

In addition, after the function call, there are once again FPU problems. Should I include floating point operations that clean up the FPU position after each new function? Is there any compiler flag that can in some way affect the FPU?

At this point I am grateful to any other tips and tricks.

EDIT: I've managed to avoid the problem by calling the first thing in the assembly function EMMS the top function. In this way, the FPU has been removed from any MMX-related waste which can not be made in the environment or, it is called from my code. It seems that the stage of the FPU is nothing which to take.

// frank

If you are using a Windows query, the conference quarters and QueryFormancyFactory functions that support MMX, after interrogation of frequency / counter and try to insert female instruction before calculation.

  __shm femms  

I have had trouble with these functions, before they were compiling 64 bit using MMX And the floating point was not clearing the flag / state.

This situation can also happen when there are 64 bit arithmetic between floating point operations.


Comments