aboutsummaryrefslogtreecommitdiffstats
path: root/src/floatfns.c
diff options
context:
space:
mode:
authorPaul Eggert2015-08-01 00:26:37 -0700
committerPaul Eggert2015-08-01 00:27:15 -0700
commitf55ce98975d155cd70ac2deff4d4b7e562def12a (patch)
treede438f922fa5d1589226844895d52d1c05ec8c5f /src/floatfns.c
parenteb0f65b4fbbea60100b53cb40a1d7138d47ad0d2 (diff)
downloademacs-f55ce98975d155cd70ac2deff4d4b7e562def12a.tar.gz
emacs-f55ce98975d155cd70ac2deff4d4b7e562def12a.zip
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.c16
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,
377 return arg; 377 return arg;
378} 378}
379 379
380/* With C's /, the result is implementation-defined if either operand
381 is negative, so take care with negative operands in the following
382 integer functions. */
383
384static EMACS_INT 380static EMACS_INT
385ceiling2 (EMACS_INT i1, EMACS_INT i2) 381ceiling2 (EMACS_INT i1, EMACS_INT i2)
386{ 382{
387 return (i2 < 0 383 return i1 / i2 + ((i1 % i2 != 0) & ((i1 < 0) == (i2 < 0)));
388 ? (i1 < 0 ? ((-1 - i1) / -i2) + 1 : - (i1 / -i2))
389 : (i1 <= 0 ? - (-i1 / i2) : ((i1 - 1) / i2) + 1));
390} 384}
391 385
392static EMACS_INT 386static EMACS_INT
393floor2 (EMACS_INT i1, EMACS_INT i2) 387floor2 (EMACS_INT i1, EMACS_INT i2)
394{ 388{
395 return (i2 < 0 389 return i1 / i2 - ((i1 % i2 != 0) & ((i1 < 0) != (i2 < 0)));
396 ? (i1 <= 0 ? -i1 / -i2 : -1 - ((i1 - 1) / -i2))
397 : (i1 < 0 ? -1 - ((-1 - i1) / i2) : i1 / i2));
398} 390}
399 391
400static EMACS_INT 392static EMACS_INT
401truncate2 (EMACS_INT i1, EMACS_INT i2) 393truncate2 (EMACS_INT i1, EMACS_INT i2)
402{ 394{
403 return (i2 < 0 395 return i1 / i2;
404 ? (i1 < 0 ? -i1 / -i2 : - (i1 / -i2))
405 : (i1 < 0 ? - (-i1 / i2) : i1 / i2));
406} 396}
407 397
408static EMACS_INT 398static EMACS_INT