Blame sysdeps/ieee754/ldbl-128ibm/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
/*
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 <math_ldbl_opt.h>
Packit 6c4009
#include <fix-int-fp-convert-zero.h>
Packit 6c4009
Packit 6c4009
long double
Packit 6c4009
__logbl (long double x)
Packit 6c4009
{
Packit 6c4009
  int64_t hx, hxs, rhx;
Packit 6c4009
  double xhi, xlo;
Packit 6c4009
Packit 6c4009
  ldbl_unpack (x, &xhi, &xlo;;
Packit 6c4009
  EXTRACT_WORDS64 (hx, xhi);
Packit 6c4009
  hxs = hx;
Packit 6c4009
  hx &= 0x7fffffffffffffffLL;	/* high |x| */
Packit 6c4009
  if (hx == 0)
Packit 6c4009
    return -1.0 / fabs (x);
Packit 6c4009
  if (hx >= 0x7ff0000000000000LL)
Packit 6c4009
    return x * x;
Packit 6c4009
  if (__glibc_unlikely ((rhx = hx >> 52) == 0))
Packit 6c4009
    {
Packit 6c4009
      /* POSIX specifies that denormal number is treated as
Packit 6c4009
         though it were normalized.  */
Packit 6c4009
      rhx -= __builtin_clzll (hx) - 12;
Packit 6c4009
    }
Packit 6c4009
  else if ((hx & 0x000fffffffffffffLL) == 0)
Packit 6c4009
    {
Packit 6c4009
      /* If the high part is a power of 2, and the low part is nonzero
Packit 6c4009
	 with the opposite sign, the low part affects the
Packit 6c4009
	 exponent.  */
Packit 6c4009
      int64_t lx;
Packit 6c4009
      EXTRACT_WORDS64 (lx, xlo);
Packit 6c4009
      if ((hxs ^ lx) < 0 && (lx & 0x7fffffffffffffffLL) != 0)
Packit 6c4009
	rhx--;
Packit 6c4009
    }
Packit 6c4009
  if (FIX_INT_FP_CONVERT_ZERO && rhx == 1023)
Packit 6c4009
    return 0.0L;
Packit 6c4009
  return (long double) (rhx - 1023);
Packit 6c4009
}
Packit 6c4009
#ifndef __logbl
Packit 6c4009
long_double_symbol (libm, __logbl, logbl);
Packit 6c4009
#endif