From f55ce98975d155cd70ac2deff4d4b7e562def12a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 1 Aug 2015 00:26:37 -0700 Subject: [PATCH] Simplify by assuming C99 integer division * src/floatfns.c (ceiling2, floor2, truncate2): Assume C99 (i.e., Fortran) semantics for integer division. This simplifies the code. --- src/floatfns.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/floatfns.c b/src/floatfns.c index 072e85776b5..63d35b8ad6b 100644 --- a/src/floatfns.c +++ b/src/floatfns.c @@ -377,32 +377,22 @@ rounding_driver (Lisp_Object arg, Lisp_Object divisor, return arg; } -/* With C's /, the result is implementation-defined if either operand - is negative, so take care with negative operands in the following - integer functions. */ - static EMACS_INT ceiling2 (EMACS_INT i1, EMACS_INT i2) { - return (i2 < 0 - ? (i1 < 0 ? ((-1 - i1) / -i2) + 1 : - (i1 / -i2)) - : (i1 <= 0 ? - (-i1 / i2) : ((i1 - 1) / i2) + 1)); + return i1 / i2 + ((i1 % i2 != 0) & ((i1 < 0) == (i2 < 0))); } static EMACS_INT floor2 (EMACS_INT i1, EMACS_INT i2) { - return (i2 < 0 - ? (i1 <= 0 ? -i1 / -i2 : -1 - ((i1 - 1) / -i2)) - : (i1 < 0 ? -1 - ((-1 - i1) / i2) : i1 / i2)); + return i1 / i2 - ((i1 % i2 != 0) & ((i1 < 0) != (i2 < 0))); } static EMACS_INT truncate2 (EMACS_INT i1, EMACS_INT i2) { - return (i2 < 0 - ? (i1 < 0 ? -i1 / -i2 : - (i1 / -i2)) - : (i1 < 0 ? - (-i1 / i2) : i1 / i2)); + return i1 / i2; } static EMACS_INT -- 2.39.2