diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2015-08-01 00:26:37 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2015-08-01 00:27:15 -0700 |
commit | f55ce98975d155cd70ac2deff4d4b7e562def12a (patch) | |
tree | de438f922fa5d1589226844895d52d1c05ec8c5f /src/floatfns.c | |
parent | eb0f65b4fbbea60100b53cb40a1d7138d47ad0d2 (diff) | |
download | emacs-f55ce98975d155cd70ac2deff4d4b7e562def12a.tar.gz |
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.
Diffstat (limited to 'src/floatfns.c')
-rw-r--r-- | src/floatfns.c | 16 |
1 files 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 |