0

I am trying to port an old project from Visual Studio 2010 to Visual Studio 2015. The problem is that snprintf (used with format "%.15g") rounds doubles differently than it used to do with Visual Studio 2010.

There are two problems:

  1. The e-notation changed from e.g. 12345e005 to 12345e05

  2. Doubles like 105.52361792790150 are now converted to "105.523617927901" instead of "105.523617927902".

I found the reason for the "missing" zero digit:

Microsoft changed it intentionally to be more standard compliant: https://blogs.msdn.microsoft.com/vcblog/2014/06/18/c-runtime-crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1/ (see "Exponent Formatting")

I implemented a solution to add the missing zero digit, but I can't find a solution for the different rounding behavior.

Is there any way to change the rounding behavior to the "old style"? I tried std::fesetround but it seems to have no effect on snprintf rounding.

  • Check you are using the same compiler options that effect the precision of floating point operations, the defaults for these might have changed. Specifically check the `/fp` switch: https://msdn.microsoft.com/en-us/library/e7s85ffb.aspx – Richard Critten Feb 03 '18 at 13:30
  • Thanks, but it makes no difference which /fp flag I use. – Mathias Kogler Feb 03 '18 at 13:47

0 Answers0