https://bugs.winehq.org/show_bug.cgi?id=37913
Bug ID: 37913 Summary: Inconsistent rounding behaviour for sprintf Product: Wine Version: unspecified Hardware: x86 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: msvcp Assignee: wine-bugs@winehq.org Reporter: christopherwuy@gmail.com Distribution: ---
sample source code and output demonstrating the problem: #include <iostream> #include <stdio.h> using namespace std; int main() { double a; a = 3.5; char *tmp = new char(100); char fmt[18] = " is %.0f"; sprintf(tmp, fmt, a); cout<<endl<<a<<tmp<<endl<<endl;
a = -4.5; sprintf(tmp, fmt, a); cout<<endl<<a<<tmp<<endl<<endl;
a = -0.5; sprintf(tmp, fmt, a); cout<<endl<<a<<tmp<<endl<<endl;
a = 2597.625; printf("%.3f", a); sprintf(tmp, " is %.2lf", a); cout<<tmp<<endl<<endl; }
This code running by wine 's Output is: 3.5 is 4 -4.5 is -4 -0.5 is -0 2597.625 is 2597.62
while windows' output is: 3.5 is 4 -4.5 is -5 -0.5 is -1 2597.625 is 2597.63
It indicated that Wine's sprintf used rounding rule which is Round half to even, while windows used Round half away from zero. You can find a detailed discussion of 'similar bug' form https://sourceware.org/bugzilla/show_bug.cgi?id=4943
https://bugs.winehq.org/show_bug.cgi?id=37913
christopherwuy@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |christopherwuy@gmail.com, | |piotr@codeweavers.com
https://bugs.winehq.org/show_bug.cgi?id=37913
tiago tiagoaparecido007@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |tiagoaparecido007@gmail.com
https://bugs.winehq.org/show_bug.cgi?id=37913
Piotr Caban piotr.caban@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |piotr.caban@gmail.com Component|msvcp |msvcrt
https://bugs.winehq.org/show_bug.cgi?id=37913
Gijs Vermeulen gijsvrm@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Version|unspecified |1.7.34 Ever confirmed|0 |1
--- Comment #1 from Gijs Vermeulen gijsvrm@gmail.com --- Still present with wine-5.14, results are still the same on both Wine and Windows.
https://bugs.winehq.org/show_bug.cgi?id=37913
--- Comment #2 from Piotr Caban piotr.caban@gmail.com --- (In reply to Gijs Vermeulen from comment #1)
Still present with wine-5.14, results are still the same on both Wine and Windows.
The bug should be already fixed. Please retest in wine 5.15 (it works for me with current wine, I didn't check when it was fixed exactly but I'm expecting that it was already working correctly in wine-5.14). Please also note that the output on windows changed when newest ucrtbase is used.
https://bugs.winehq.org/show_bug.cgi?id=37913
--- Comment #3 from Gijs Vermeulen gijsvrm@gmail.com --- (In reply to Piotr Caban from comment #2)
The bug should be already fixed. Please retest in wine 5.15 (it works for me with current wine, I didn't check when it was fixed exactly but I'm expecting that it was already working correctly in wine-5.14). Please also note that the output on windows changed when newest ucrtbase is used.
Gijss-MacBook-Pro:Desktop gverm$ x86_64-w64-mingw32-g++ -static sprintf.cpp Gijss-MacBook-Pro:Desktop gverm$ $WINE a.exe 3.5 is 4 -4.5 is -4 -0.5 is -0 2597.625 is 2597.62
These are the steps I used and result I got with wine-5.15. If this is the expected result, this bug can be resolved.
https://bugs.winehq.org/show_bug.cgi?id=37913
Piotr Caban piotr.caban@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED Fixed by SHA1| |1bc6f0c86174cf1b5e47f1f1324 | |a3f733e0658a1
--- Comment #4 from Piotr Caban piotr.caban@gmail.com --- You're not using wine sprintf implementation when the test is compiled this way. You can see that it works by changing "cout<<..." lines with printf and compiling without -static switch.
Marking the bug as fixed.
https://bugs.winehq.org/show_bug.cgi?id=37913
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #5 from Alexandre Julliard julliard@winehq.org --- Closing bugs fixed in 5.16.