c++ - strange results with /fp:fast -


We have some code that looks like this:

  Inline ant calms_group ( Double X) {If (x> 0.0) {// Some Return 1; } Else {// return something else 0; Unfortunately, when using Flag  / fp: fast , we get the  calc_something (0) == 1  so we are clearly taking the wrong code path This is only when we use the method on many points in our code with different standards, so I think there is some inflammatory customization here from the compiler (Microsoft Visual Studio 2008, SP1). 

In addition, the above problem is solved when we use the interface

  inline inc calc_something (const double & x) {  P>) but I do not know whether this fix is ​​strange behavior can anyone explain this behavior? If I do not understand what is happening then we have to delete the  / fp: fast  switch, but it will slow down our application very much. 

y = x + 20; sit in that comparison. Y = y - 20; y is already on the FP stack, so instead of load x the compiler compares against just y . But due to rounding errors, y is not enough 0.0 as it is supposed to be, and you get strange results. A better explanation for

: C ++ FAQ from Light. This is part of what I am trying to achieve, I just do not remember, as far as I've read it yet.

Changing it in a reference context is fine because the compiler is concerned about aliasing. It forces a load from x because it can not assume that its value has not changed at any point after making it y , and since X is exactly the same as 0.0 [which is worthy of representation in every floating point format], I'm familiar with) spherical errors disappear.

I'm pretty sure that MS provides you a program that lets you set up FP flags based on a per-function. Or you can move this routine to a different file and give custom flags of that file. Either way, this can prevent your entire program from being victimized just to keep a regular happy.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -