summaryrefslogtreecommitdiff
path: root/src/floatfns.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2019-01-06 16:23:41 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2019-01-06 16:25:40 -0800
commit202bd7bff2710b98cde4ae4b6e1f6de9818591f8 (patch)
tree5b58e9df997c158ccd6887a1c5ac81533040744f /src/floatfns.c
parentb0b483d714e87ee0a4572f9c541514a1ac1a8226 (diff)
downloademacs-202bd7bff2710b98cde4ae4b6e1f6de9818591f8.tar.gz
Fix logb on zero, infinite, NaN args
Change logb to return -infinity, +infinity, and NaN respectively. Formerly logb returned an extreme fixnum to represent infinity, but this is no longer the right thing to do now that we have bignums and there is no extreme integer. * doc/lispref/numbers.texi (Float Basics), etc/NEWS: Document. * src/floatfns.c (Flogb): Implement this.
Diffstat (limited to 'src/floatfns.c')
-rw-r--r--src/floatfns.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/floatfns.c b/src/floatfns.c
index 2d76b97eec7..a913aad5aac 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -306,27 +306,22 @@ This is the same as the exponent of a float. */)
if (FLOATP (arg))
{
double f = XFLOAT_DATA (arg);
-
if (f == 0)
- value = MOST_NEGATIVE_FIXNUM;
- else if (isfinite (f))
- {
- int ivalue;
- frexp (f, &ivalue);
- value = ivalue - 1;
- }
- else
- value = MOST_POSITIVE_FIXNUM;
+ return make_float (-HUGE_VAL);
+ if (!isfinite (f))
+ return f < 0 ? make_float (-f) : arg;
+ int ivalue;
+ frexp (f, &ivalue);
+ value = ivalue - 1;
}
- else if (BIGNUMP (arg))
+ else if (!FIXNUMP (arg))
value = mpz_sizeinbase (XBIGNUM (arg)->value, 2) - 1;
else
{
- eassert (FIXNUMP (arg));
- EMACS_INT i = eabs (XFIXNUM (arg));
- value = (i == 0
- ? MOST_NEGATIVE_FIXNUM
- : EMACS_UINT_WIDTH - 1 - ecount_leading_zeros (i));
+ EMACS_INT i = XFIXNUM (arg);
+ if (i == 0)
+ return make_float (-HUGE_VAL);
+ value = EMACS_UINT_WIDTH - 1 - ecount_leading_zeros (eabs (i));
}
return make_fixnum (value);