#include <stdio.h>
int main()
{
float f = 1717.7890625;
printf( "%.6f", f );
return 0;
}
I compiled this code with Visual Studio 19 (16.9.2) for x64 arch and ran the result on two my Windows 10 PCs:
1717.789063
1717.789063
Release: 1717.789062
What is the cause of the difference between the Debug and Release results on new version? How can I fix it to make results identical on both versions?
Addition: The code:
#include <stdio.h>
int main()
{
double f = 0.25;
printf( "%.1f", f );
return 0;
}
has the same behavior on new vs old Win10 versions. I suggest, that's an error in newer ucrtbase.dll version
I found the cause of such different behavior of program between windows versions and debug/release modes.
The new windows update (19041.* if I understand correctly) changed rounding rules for fractional part of floating point types: previously it was rounding to greater in case of end with 5: 1.25 -> 1.3
, but now it's rounding to nearest even: 1.25 -> 1.2
, 1.35 -> 1.4
.
To understand the difference between debug and release on new Win 10 version it's needed to notice about the ucrtbase.dll usage and update rules.
So, the solution is to install new Windows 10 SDK on new Windows 10 version to achieve the same behavior or switch printf() function to fmt::printf() function from https://github.com/fmtlib/fmt, for example, to make result to be the same on all windows versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With