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
\(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);
}
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);
}
(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)