Sorry for probably stupid question, as I am C# developer it is really difficult for me to find some ideas.
We are in progress of migration from VC++ 2013 to VC++ 2019. We have 2 similar VMs with VC++2013 and VC++2019 installed. Projects are using VC++2019 already. When running on 2 VMs results for simple evaluation are different:
CString Value;
int precision = 8;
double number = 50.634765625;
String^ RetValue;
Value.Format(_T("%.*f"), precision, number);
RetValue = gcnew String(Value.GetString());
On one VM (Win 7 64bit) we have RetValue "50.63476563" on another VM (win10 64bit) we have - "50.63476562" all tools I expect are the same (difficult to say 100% as there a lot installed, but most important c++ are).
When converting and running projects under VS2013 results on both VM are the same - "50.63476563".
Are there any option settings that control formatting? Or why in case of one VM truncation was selected in favor of rounding?
UPDATE So the problem is really related to VS2013/VS2019 difference. I found why we have different results on 2 VMs using the same VS2019. So:
- VS2013 rounding of 50.634765625 == VS 2019 rounding for Release
- VS2013 rounding of 50.634765625 != VS 2019 rounding for Debug
in both cases rounding direction is to nearest. So MSFT interprets to nearest differently in Release/Debug. C++ compiler option that makes difference /MD vs /MDd.
Could not find any other way except of switching to /MD to force rounding go old way for whole project in debug.
String^
-- Change or update your tags. This is not C++. – SamonsCString
to a C++/CLIString^
isn't relevant to the issue. – Generalissimostd::fegetround
returns on each system en.cppreference.com/w/cpp/numeric/fenv/feround – Serviceable