Function: logb

logb is a function defined in floatfns.c.

Signature

(logb ARG)

Documentation

Returns largest integer <= the base 2 log of the magnitude of ARG.

This is the same as the exponent of a float.

Other relevant functions are documented in the number group.

Probably introduced at or before Emacs version 26.1.

Shortdoc

;; number
(logb 10.5)
    => 3

Source Code

// Defined in /usr/src/emacs/src/floatfns.c
{
  EMACS_INT value;
  CHECK_NUMBER (arg);

  if (FLOATP (arg))
    {
      double f = XFLOAT_DATA (arg);
      if (f == 0)
	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 (!FIXNUMP (arg))
    value = mpz_sizeinbase (*xbignum_val (arg), 2) - 1;
  else
    {
      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);
}