]> git.eshelyaron.com Git - emacs.git/commitdiff
ffloor etc. now accept only floats
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 5 Mar 2017 21:29:28 +0000 (13:29 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 5 Mar 2017 21:31:33 +0000 (13:31 -0800)
* etc/NEWS: Say why.
* src/floatfns.c (Ffceiling, Fffloor, Ffround, Fftruncate):
Require arg to be float.
* test/src/floatfns-tests.el (fround-fixnum): Check this.

etc/NEWS
src/floatfns.c
test/src/floatfns-tests.el

index fe02236ecc2a408e9f27ca006c72c81351a7b15c..8f7356f3e038ed780936ccdb12275da9a4a403f3 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -907,6 +907,12 @@ compares their numerical values.  According to this predicate,
 due to internal rounding errors.  For example, (< most-positive-fixnum
 (+ 1.0 most-positive-fixnum)) now correctly returns t on 64-bit hosts.
 
+---
+** The functions 'ffloor', 'fceiling', 'ftruncate' and 'fround' now
+accept only floating-point arguments, as per their documentation.
+Formerly, they quietly accepted integer arguments and sometimes
+returned nonsensical answers, e.g., (< N (ffloor N)) could return t.
+
 ---
 ** On hosts like GNU/Linux x86-64 where a 'long double' fraction
 contains at least EMACS_INT_WIDTH - 3 bits, 'format' no longer returns
index 9ae810669effcf021b81e445771e3d85c0d1e930..4c09036ac79c4c8952391beed24acfa1fda9a1dd 100644 (file)
@@ -504,17 +504,19 @@ DEFUN ("fceiling", Ffceiling, Sfceiling, 1, 1, 0,
 \(Round toward +inf.)  */)
   (Lisp_Object arg)
 {
-  double d = extract_float (arg);
+  CHECK_FLOAT (arg);
+  double d = XFLOAT_DATA (arg);
   d = ceil (d);
   return make_float (d);
 }
 
 DEFUN ("ffloor", Fffloor, Sffloor, 1, 1, 0,
        doc: /* Return the largest integer no greater than ARG, as a float.
-\(Round towards -inf.)  */)
+\(Round toward -inf.)  */)
   (Lisp_Object arg)
 {
-  double d = extract_float (arg);
+  CHECK_FLOAT (arg);
+  double d = XFLOAT_DATA (arg);
   d = floor (d);
   return make_float (d);
 }
@@ -523,17 +525,19 @@ DEFUN ("fround", Ffround, Sfround, 1, 1, 0,
        doc: /* Return the nearest integer to ARG, as a float.  */)
   (Lisp_Object arg)
 {
-  double d = extract_float (arg);
+  CHECK_FLOAT (arg);
+  double d = XFLOAT_DATA (arg);
   d = emacs_rint (d);
   return make_float (d);
 }
 
 DEFUN ("ftruncate", Fftruncate, Sftruncate, 1, 1, 0,
        doc: /* Truncate a floating point number to an integral float value.
-Rounds the value toward zero.  */)
+\(Round toward zero.)  */)
   (Lisp_Object arg)
 {
-  double d = extract_float (arg);
+  CHECK_FLOAT (arg);
+  double d = XFLOAT_DATA (arg);
   d = emacs_trunc (d);
   return make_float (d);
 }
index cdfb8244f5255ceb4963a4f1dbe4d4d3792ed89e..de3e44314f970280c2f4d6eb0185a958e8104a31 100644 (file)
 (ert-deftest logb-extreme-fixnum ()
   (should (= (logb most-negative-fixnum) (1+ (logb most-positive-fixnum)))))
 
+(ert-deftest fround-fixnum ()
+  (should-error (ffloor 0) :type 'wrong-type-argument)
+  (should-error (fceiling 0) :type 'wrong-type-argument)
+  (should-error (ftruncate 0) :type 'wrong-type-argument)
+  (should-error (fround 0) :type 'wrong-type-argument))
+
 (provide 'floatfns-tests)