Clarify by-hand rounded %0.1f formatting

Coverity is rightly pointing out that it is not clear that `double` math is wanted, where the conversion from `long long` to `double` should occur, and where integer remainders are discarded.

Most compilers will get it right, but humans may find it confusing or unexpected.

* Did some algebra to reduce half-bit errors.

* Added a cast to make the conversion explicit.

* Aligned turn expected damage with running expected damage so both are the same representation.

Closes CID 1380164
This commit is contained in:
Gregory A Lundberg 2017-10-31 14:20:23 -05:00
parent 28cfa72de0
commit 520e617d8a

View file

@ -145,7 +145,7 @@ void statistics_dialog::add_damage_row(
std::ostringstream str;
str << damage << " / "
<< (expected * 10 + shift / 2) / shift * 0.1
<< static_cast<double>(((expected * 20) + shift) / (2 * shift)) * 0.1
<< " " // TODO: should probably make this two columns
<< ((dsa < 0) ^ (expected < 0) ? "" : "+")
<< (expected == 0 ? 0 : 100 * dsa / expected) << '%';
@ -157,7 +157,7 @@ void statistics_dialog::add_damage_row(
if(show_this_turn) {
str << turn_damage << " / "
<< (turn_expected * 10 + shift / 2) / shift / 10
<< static_cast<double>(((turn_expected * 20) + shift) / (2 * shift)) * 0.1
<< " " // TODO: should probably make this two columns
<< ((dst < 0) ^ (turn_expected < 0) ? "" : "+")
<< (turn_expected == 0 ? 0 : 100 * dst / turn_expected) << '%';