Blame sysdeps/ieee754/ldbl-128/s_logbl.c

Packit 6c4009
/* s_logbl.c -- long double version of s_logb.c.
Packit 6c4009
 * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * ====================================================
Packit 6c4009
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
Packit 6c4009
 *
Packit 6c4009
 * Developed at SunPro, a Sun Microsystems, Inc. business.
Packit 6c4009
 * Permission to use, copy, modify, and distribute this
Packit 6c4009
 * software is freely granted, provided that this notice
Packit 6c4009
 * is preserved.
Packit 6c4009
 * ====================================================
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#if defined(LIBM_SCCS) && !defined(lint)
Packit 6c4009
static char rcsid[] = "$NetBSD: $";
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * long double logbl(x)
Packit 6c4009
 * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
Packit 6c4009
 * Use ilogb instead.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <math.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
#include <libm-alias-ldouble.h>
Packit 6c4009
Packit 6c4009
_Float128
Packit 6c4009
__logbl (_Float128 x)
Packit 6c4009
{
Packit 6c4009
  int64_t lx, hx, ex;
Packit 6c4009
Packit 6c4009
  GET_LDOUBLE_WORDS64 (hx, lx, x);
Packit 6c4009
  hx &= 0x7fffffffffffffffLL;	/* high |x| */
Packit 6c4009
  if ((hx | lx) == 0)
Packit 6c4009
    return -1.0 / fabsl (x);
Packit 6c4009
  if (hx >= 0x7fff000000000000LL)
Packit 6c4009
    return x * x;
Packit 6c4009
  if ((ex = hx >> 48) == 0)	/* IEEE 754 logb */
Packit 6c4009
    {
Packit 6c4009
      /* POSIX specifies that denormal number is treated as
Packit 6c4009
         though it were normalized.  */
Packit 6c4009
      int ma;
Packit 6c4009
      if (hx == 0)
Packit 6c4009
	ma = __builtin_clzll (lx) + 64;
Packit 6c4009
      else
Packit 6c4009
	ma = __builtin_clzll (hx);
Packit 6c4009
      ex -= ma - 16;
Packit 6c4009
    }
Packit 6c4009
  return (_Float128) (ex - 16383);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
libm_alias_ldouble (__logb, logb)