gbranden pushed a commit to branch master
in repository groff.
commit 05bcb560c8337e7b417c9d3497199ca20fe13bc1
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Jul 25 14:31:39 2024 -0500
src/roff/troff/number.cpp: Slightly refactor.
* src/roff/troff/number.cpp (vunits::vunits, hunits::hunits): Move
common subexpression to a temporary variable to prepare for reuse in
C23 checked artihmetic macros.
---
ChangeLog | 6 ++++++
src/roff/troff/number.cpp | 20 ++++++++++++--------
2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a20737e48..88d6cd3be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-07-25 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/number.cpp (vunits::vunits, hunits::hunits):
+ Move common subexpression to a temporary variable to prepare for
+ reuse in C23 checked artihmetic macros.
+
2024-07-25 G. Branden Robinson <[email protected]>
[troff]: Enforce minimum page length.
diff --git a/src/roff/troff/number.cpp b/src/roff/troff/number.cpp
index a82a4eeda..7f43c0772 100644
--- a/src/roff/troff/number.cpp
+++ b/src/roff/troff/number.cpp
@@ -656,24 +656,28 @@ units scale(units n, units x, units y)
vunits::vunits(units x)
{
- // Don't depend on rounding direction when dividing negative integers.
if (vresolution == 1)
n = x;
- else
+ else {
+ // Don't depend on rounding direction when dividing neg integers.
+ int vcrement = (vresolution / 2) - 1;
n = (x < 0
- ? -((-x + (vresolution / 2) - 1) / vresolution)
- : (x + (vresolution / 2) - 1) / vresolution);
+ ? -((-x + vcrement) / vresolution)
+ : (x + vcrement) / vresolution);
+ }
}
hunits::hunits(units x)
{
- // Don't depend on rounding direction when dividing negative integers.
if (hresolution == 1)
n = x;
- else
+ else {
+ // Don't depend on rounding direction when dividing neg integers.
+ int hcrement = (hresolution / 2) - 1;
n = (x < 0
- ? -((-x + (hresolution / 2) - 1) / hresolution)
- : (x + (hresolution / 2) - 1) / hresolution);
+ ? -((-x + hcrement) / hresolution)
+ : (x + hcrement) / hresolution);
+ }
}
// Local Variables:
_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit