summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/pp.c b/pp.c
index 25d3a319cd..643a8758b7 100644
--- a/pp.c
+++ b/pp.c
@@ -3047,13 +3047,12 @@ PP(pp_abs)
if (iv >= 0) {
uv = (UV)iv;
} else {
- if (iv != IV_MIN) {
- uv = (UV)-iv;
- } else {
- /* 2s complement assumption. Also, not really needed as
- IV_MIN and -IV_MIN should both be %100...00 and NV-able */
- uv = (UV)IV_MIN;
- }
+ /* "(UV)-(iv + 1) + 1" below is mathematically "-iv", but
+ transformed so that every subexpression will never trigger
+ overflows even on 2's complement representation (note that
+ iv is always < 0 here), and modern compilers could optimize
+ this to a single negation. */
+ uv = (UV)-(iv + 1) + 1;
}
}
set_uv: