-
Notifications
You must be signed in to change notification settings - Fork 4
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
Proper rounding implementation #23
Conversation
...in accordance with Basisregelwerk page 13 ("Rundungen"). The previous implementation relies on `string.format("%.0f", x)` whose behaviour is inconsistent accross Lua versions.
- common.render_delta() used to generate the wrong sign for non-zero values in [-0.5, 0.5]. - Use local variable for sign character to better describe what's happening.
- Use a *local* variable to store intermediary results. - Emit "&" and the integral value with a single tex.sprint() since the latter can't result in special characters.
that previously involved `math.floor(x + 0.5)` or `string.format("%.0f", x)`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generell okay, da war schon viel Wildwuchs in den Rundungsmechanismen.
Allerdings zieht ungerade eBE jetzt einen Punkt zu viel von der AT ab, das müsstest du noch fixen.
src/kampfbogen.lua
Outdated
@@ -158,14 +159,14 @@ nahkampf_render[11]= {false, function(v, talent, ebe) | |||
if talent == nil or #talent < 4 or atb == "" or #v < 8 then | |||
return | |||
end | |||
tex.sprint(-2, atpa_mod(atb - common.round(ebe/2, true), talent.AT, v["TP/KK Schwelle"], v["TP/KK Schritt"], v["WM AT"], art(v), talent.Spezialisierungen)) | |||
tex.sprint(-2, atpa_mod(atb - math.round(ebe/2, true), talent.AT, v["TP/KK Schwelle"], v["TP/KK Schritt"], v["WM AT"], art(v), talent.Spezialisierungen)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
math.round
hat den zweiten Parameter nicht mehr, ist also an der Stelle falsch und müsste statt dessen math.floor
sein.
Sonst wird bei einer ungeraden eBE ein Punkt zu viel von der AT abgezogen.
src/kampfbogen.lua
Outdated
@@ -252,7 +253,7 @@ local waffenlos_render = { | |||
added = added + 1 | |||
end | |||
end | |||
tex.sprint(-2, atpa_mod(atb - common.round(ebe/2, true), talent.AT, v["TP/KK Schwelle"], v["TP/KK Schritt"], 0)) | |||
tex.sprint(-2, atpa_mod(atb - math.round(ebe/2, true), talent.AT, v["TP/KK Schwelle"], v["TP/KK Schritt"], 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selbe Geschichte wie oben.
Danke für die Kommentare! Ich kümmere mich im Verlauf der Woche um die beiden Probleme. |
Strictly speaking, the rules of distribution of effective encumberance onto AT/PA values use integer floor/ceil division by two rather than rounding (Basisregelwerk, p. 137). So that's what we'll use in the implementation.
…in accordance with Basisregelwerk page 13 (“Rundungen”).
The previous implementation relies on
string.format("%.0f", x)
whose behaviour is inconsistent across Lua versions.Other rounding uses idioms like
math.floor(x + 0.5)
which is fine for DSA number ranges but generally inexact,(n + d2) // d
(whered
andd2
are positive integer literals andd2
is (d
÷2) rounded down) which is a bit difficult to read and error-prone.Potential caveat: this implementation rounds halfway cases away from zero while the rules state that (barring special cases) they should be rounded “up”, i. e. towards positive infinity. However, I have yet to see a rule that requires the rounding of negative values (to any other value than zero); instances where negative modifiers need rounding (e. g. encumbrance), the rounding is supposed to be applied to their absolute values, i. e. away from zero.