ffloor etc. now accept only floats
* 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.
This commit is contained in:
parent
788a5b8447
commit
53f3dd66f1
3 changed files with 22 additions and 6 deletions
6
etc/NEWS
6
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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -28,4 +28,10 @@
|
|||
(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)
|
||||
|
|
Loading…
Add table
Reference in a new issue