(root)/
glibc-2.38/
sysdeps/
ieee754/
ldbl-128/
e_ilogbl.c
       1  /* s_ilogbl.c -- long double version of s_ilogb.c.
       2   */
       3  
       4  /*
       5   * ====================================================
       6   * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
       7   *
       8   * Developed at SunPro, a Sun Microsystems, Inc. business.
       9   * Permission to use, copy, modify, and distribute this
      10   * software is freely granted, provided that this notice
      11   * is preserved.
      12   * ====================================================
      13   */
      14  
      15  #if defined(LIBM_SCCS) && !defined(lint)
      16  static char rcsid[] = "$NetBSD: $";
      17  #endif
      18  
      19  /* ilogbl(long double x)
      20   * return the binary exponent of non-zero x
      21   * ilogbl(0) = FP_ILOGB0
      22   * ilogbl(NaN) = FP_ILOGBNAN (no signal is raised)
      23   * ilogbl(+-Inf) = INT_MAX (no signal is raised)
      24   */
      25  
      26  #include <limits.h>
      27  #include <math.h>
      28  #include <math_private.h>
      29  
      30  int __ieee754_ilogbl (_Float128 x)
      31  {
      32  	int64_t hx,lx;
      33  	int ix;
      34  
      35  	GET_LDOUBLE_WORDS64(hx,lx,x);
      36  	hx &= 0x7fffffffffffffffLL;
      37  	if(hx <= 0x0001000000000000LL) {
      38  	    if((hx|lx)==0)
      39  		return FP_ILOGB0;	/* ilogbl(0) = FP_ILOGB0 */
      40  	    else			/* subnormal x */
      41  		if(hx==0) {
      42  		    for (ix = -16431; lx>0; lx<<=1) ix -=1;
      43  		} else {
      44  		    for (ix = -16382, hx<<=15; hx>0; hx<<=1) ix -=1;
      45  		}
      46  	    return ix;
      47  	}
      48  	else if (hx<0x7fff000000000000LL) return (hx>>48)-0x3fff;
      49  	else if (FP_ILOGBNAN != INT_MAX) {
      50  	    /* ISO C99 requires ilogbl(+-Inf) == INT_MAX.  */
      51  	    if (((hx^0x7fff000000000000LL)|lx) == 0)
      52  		return INT_MAX;
      53  	}
      54  	return FP_ILOGBNAN;
      55  }