]> code.delx.au - gnu-emacs/commitdiff
Fix porting inconsistency about rounding to even.
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 19 Mar 2014 21:09:08 +0000 (14:09 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 19 Mar 2014 21:09:08 +0000 (14:09 -0700)
* doc/lispref/numbers.texi (Numeric Conversions, Rounding Operations):
Document that 'round' and 'fround' round to even.
* src/floatfns.c (emacs_rint) [!HAVE_RINT]: Round to even.
This way, the unusual !HAVE_RINT case acts like the usual
HAVE_RINT case, and we can fix the documentation accordingly.

doc/lispref/ChangeLog
doc/lispref/numbers.texi
src/ChangeLog
src/floatfns.c

index 2749a521c9aab45ed52e72bee3eed616a2fce23d..25c4744c855cd422a45d9be65c3896ad63ed9cdf 100644 (file)
@@ -1,3 +1,9 @@
+2014-03-19  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Fix porting inconsistency about rounding to even.
+       * numbers.texi (Numeric Conversions, Rounding Operations):
+       Document that 'round' and 'fround' round to even.
+
 2014-03-18  Juanma Barranquero  <lekktu@gmail.com>
 
        * customize.texi (Variable Definitions): Recommend avoiding
index 1758a44baab7f5f9644ffbf9ca9c940fcda4fc97..5526ea0860ab30773167278978ea4183fbebf943 100644 (file)
@@ -534,8 +534,7 @@ This returns @var{number}, converted to an integer by rounding upward
 @defun round number &optional divisor
 This returns @var{number}, converted to an integer by rounding towards the
 nearest integer.  Rounding a value equidistant between two integers
-may choose the integer closer to zero, or it may prefer an even integer,
-depending on your machine.
+returns the even integer.
 
 @example
 (round 1.2)
@@ -803,6 +802,7 @@ returns that value as a floating-point number.
 @defun fround float
 This function rounds @var{float} to the nearest integral value,
 and returns that value as a floating-point number.
+Rounding a value equidistant between two integers returns the even integer.
 @end defun
 
 @node Bitwise Operations
index 94859f1f8fd8252f65ee90c3c530b35fbad79cea..06e4c3291b5bd8f3e4d2ffbefb90c0ab73123393 100644 (file)
@@ -1,3 +1,10 @@
+2014-03-19  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Fix porting inconsistency about rounding to even.
+       * floatfns.c (emacs_rint) [!HAVE_RINT]: Round to even.
+       This way, the unusual !HAVE_RINT case acts like the usual
+       HAVE_RINT case, and we can fix the documentation accordingly.
+
 2014-03-19  Eli Zaretskii  <eliz@gnu.org>
 
        * w32fns.c (reset_modifiers): Zero out keystate[] before using it.
index 4de5f480259fec42bcec676f5b696efb1e780bbf..ac0447ce6d69211f26a8e38af6b87e624429c862 100644 (file)
@@ -428,7 +428,9 @@ round2 (EMACS_INT i1, EMACS_INT i2)
 static double
 emacs_rint (double d)
 {
-  return floor (d + 0.5);
+  double d1 = d + 0.5;
+  double r = floor (d1);
+  return r - (r == d1 && fmod (r, 2) != 0);
 }
 #endif