none
Why does the string representation of floating-point numbers change after .NET update? RRS feed

  • Question

  • After Windows has updated, some calculated values have changed in the last digit, e.g. from -0.0776529085243926 to -0.0776529085243925. The change is always down by one and both even and odd numbers are affected. This seems to be related to KB4486153, as reverting this update changes the values back to the previous ones. (It may also be related to KB4512192 which was installed at the same time.)

    This change can be seen already when debugging in Visual Studio and the value is later written to an output file and changes therein as well (without running the debugger).

    I know about loss of precision in floating-point calculations, but why does this change happen after an update and how can we guarantee that future updates don't change the representation of values?

    Minimal reproducible example

    The printout below changes from -0.0776529085243926 to -0.0776529085243925 after the update.

    var output = -0.07765290852439255; Trace.WriteLine(output); // This printout changes with the update.

    Is there something I can do to get the previous behaviour while keeping the updates?

    I know about loss of precision in floating-point calculations, but why does this change happen after an update and how can we guarantee that future updates don't change the representation of values?


    This question was also posted to StackOverflow

    https://stackoverflow.com/questions/57593059/rounding-of-last-digit-changes-after-windows-net-update



    Thursday, August 22, 2019 7:31 AM

All replies

  • Hi Jaroslav,

    Welcome to the MSDN forum.

    According to your description, I tried to install the .NET Framework 4.8 and uninstall it to test with the sample code as below:

    var output = -0.07765290852439255;

    Console.WriteLine(output);

    Console.ReadLine();

    The output is the same and display ‘-0.0776529085243926’, please check the following screenshot, per this and the latest installed .NET Framework is 4.7.2:

    What’s your VS version? Please go to Help-About Microsoft Visual Studio to check and share it.

    If I made any misunderstanding, please feel free to let me know, thanks for your understanding.

    Best regards,

    Sara


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Friday, August 23, 2019 7:22 AM
    Moderator
  • Hi Sara,

    Thank you for looking into this.

    The projects Target framework is set to .NET Framework 4.6.1 and AnyCPU and I'm using VS 2015 Professional

    I tried installing and uninstalling KB4486153 and the behaviour changed with it.

    It might also be related to KB4512192, which was installed at the same time. However, on another machine, this behaviour was caused by other KB-numbers (perhaps KB4508433)

    Kind regards,

    Jaroslav

    Friday, August 23, 2019 3:48 PM
  • Hi Jaroslav,

    Thanks for your detail information.

    I also tried to test my shared code in VS 2015 like yours, it still display ‘-0.0776529085243926’. Do you have VS 2017 or 2019 on the same computer? You can have a try with different VS version and check if this issue is specific to VS 2015 or not.

    Best regards,

    Sara



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Monday, August 26, 2019 9:54 AM
    Moderator