From cca0e79ea81712786f92a6668c61001e60d24f32 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 8 Jul 2018 00:10:54 -0600 Subject: [PATCH] Make logb handle bignums * src/floatfns.c (Flogb): Handle bignums. * test/src/floatfns-tests.el (bignum-logb): New test. --- src/floatfns.c | 5 ++++- test/src/floatfns-tests.el | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/floatfns.c b/src/floatfns.c index 6d7fc1452d3..9a5f0a3ad2f 100644 --- a/src/floatfns.c +++ b/src/floatfns.c @@ -328,7 +328,7 @@ This is the same as the exponent of a float. */) (Lisp_Object arg) { EMACS_INT value; - CHECK_FIXNUM_OR_FLOAT (arg); + CHECK_NUMBER (arg); if (FLOATP (arg)) { @@ -345,8 +345,11 @@ This is the same as the exponent of a float. */) else value = MOST_POSITIVE_FIXNUM; } + else if (BIGNUMP (arg)) + value = mpz_sizeinbase (XBIGNUM (arg)->value, 2) - 1; else { + eassert (FIXNUMP (arg)); EMACS_INT i = eabs (XINT (arg)); value = (i == 0 ? MOST_NEGATIVE_FIXNUM diff --git a/test/src/floatfns-tests.el b/test/src/floatfns-tests.el index 0911ff46515..7714c05d60a 100644 --- a/test/src/floatfns-tests.el +++ b/test/src/floatfns-tests.el @@ -42,4 +42,8 @@ (should (= most-positive-fixnum (- (abs most-negative-fixnum) 1)))) +(ert-deftest bignum-logb () + (should (= (+ (logb most-positive-fixnum) 1) + (logb (+ most-positive-fixnum 1))))) + (provide 'floatfns-tests) -- 2.39.2