Will the scope of floating point variables affect their values?

前端 未结 3 2035
Happy的楠姐
Happy的楠姐 2020-12-13 01:44

If we execute the following C# code on a console application, we will get a message as The sums are Not equal.

If we execute it after uncommenting the l

3条回答
  •  旧时难觅i
    2020-12-13 02:26

    (Not a real answer but hopefully some supporting documentation)

    Configuration: Core i7, Windows 8.1, Visual Studio 2013

    Platform x86:

    Version      Optimized Code?        Debugger Enabled?          Outcome
    4.5.1        Yes                    No                         Not equal
    4.5.1        Yes                    Yes                        Equal
    4.5.1        No                     No                         Equal
    4.5.1        No                     Yes                        Equal
    2.0          Yes                    No                         Not Equal
    2.0          Yes                    Yes                        Equal
    2.0          No                     No                         Equal
    2.0          No                     Yes                        Equal
    

    Platform x64:

    Version      Optimized Code?        Debugger Enabled?          Outcome
    4.5.1        Yes                    No                         Equal
    4.5.1        Yes                    Yes                        Equal
    4.5.1        No                     No                         Equal
    4.5.1        No                     Yes                        Equal
    2.0          Yes                    No                         Equal
    2.0          Yes                    Yes                        Equal
    2.0          No                     No                         Equal
    2.0          No                     Yes                        Equal
    

    The situation only seems to occur with optimized code on x86 configurations.

提交回复
热议问题