mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-28 16:21:07 -08:00
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.
This commit is contained in:
parent
eb0f65b4fb
commit
f55ce98975
1 changed files with 3 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue