-
-
Notifications
You must be signed in to change notification settings - Fork 988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatting error for round numbers in add-on manager #3871
Comments
The size is formatted with function wesnoth/src/serialization/string_utils.cpp Line 525 in 7ea1377
I believe the fix would involve using the fixed formatting mode with all compilers. |
I used gcc. |
Yes, it's possible that the actual value was slightly less than 1000 kiB. Thus, the precision was only set to three digits, and libstdc++ (GCC's standard library implementation) chose the scientific formatting mode. We should just use the fixed mode everywhere. Relying on the default mode not using scientific formatting is fragile. |
A pity it's not easy to reproduce. I could check this with MSVC on Windows and gcc on Linux. |
To test this, you could just hardcode the value to whatever you want.
|
Thanks for the pointer. The nice thing is that I don't need to download anything extra - the add-ons list download is sufficient. I saw the commit that Vultraz did and given that sevu is using gcc I focused on that, but both MSVC and gcc (with a value of 1024000) show 1000.0 KiB instead of 1e+03 KiB now. I'd say this can be closed, assuming sevu is okay with it. |
First off, 1 MiB = 1024 KiB, so the case in the report can be reproduced with values from 1000 KiB to 1023 KiB. (just add I tried to keep the number size fairly small and constant, hence the 3-digit precision, bumped to 4 digits for just the above case. This means at all times, at most 4 characters are used for the number. Unfortunately, MSVC ignores the standard saying that in default mode, the precision method specifies the number of significant digits, and takes it to mean the number of decimals instead. So for MSVC we do the next-best thing and just use fixed mode with 1 decimal, even though this can use up to 6 characters (e.g. 1000.0), and can result in fairly nonsensical precisions (1.0 bytes). Equivalent printf statements: http://cpp.sh/23ign (according to standard sections 30.7.5.2.2 and 25.4.2.2.2, also: https://en.cppreference.com/w/cpp/locale/num_put/put) I do wonder why 1024000 would return as 1e+03 KiB instead of 1000 KiB though, so I wonder what configuration is needed to produce this issue. |
Ah, I seem to have found the problem: http://cpp.sh/26hia There is a range of double values [999.5, 1000) that will display as 1000 when printed. Printing these with a precision of 4 will cause 999.5 to be printed instead, but that's less of an issue. A more robust comparison will fix this (rounding before comparing will do). We could also round all values >= 999 before printing to avoid the whole thing altogether. |
Behaviour for MSVC remains the same (fixed with 1 decimal). Fix a corner-case where [999.5, 1000) would not trigger 4-digit precision, but would be rounded to 1000 during printing, resulting in 1e+3.
Restore 3-significant-digit si_string (closes #3871)
Maybe unrelated to #3870, could proof-check if #1396 is affected or not.
It's 1000 KiB
Not really reproducible I guess ;)
The text was updated successfully, but these errors were encountered: