-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proper rounding implementation (#23)
* Implement math.round(x): nearest integer, halfway away from zero ...in accordance with Basisregelwerk page 13 ("Rundungen"). The previous implementation relies on `string.format("%.0f", x)` whose behaviour is inconsistent accross Lua versions. * Use math.round() over common.round() in trivial cases * common.render_delta(): use math.round() * common.render_delta() used to generate the wrong sign for non-zero values in [-0.5, 0.5]. - Emit "&" and the integral value with a single tex.sprint() since the latter can't result in special characters. * Remove common.round()
- Loading branch information
1 parent
7755e64
commit 7809670
Showing
8 changed files
with
62 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- Rounds to the nearest integer. Halfway cases are arounded _away_ from zero. | ||
function math.round(x) | ||
local integral, fractional = math.modf(x) | ||
if fractional >= 0.5 then | ||
return integral + 1 | ||
elseif fractional <= -0.5 then | ||
return integral - 1 | ||
end | ||
return integral | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters