1 /* 2009 for Newlib: Sun's sf_ilogb.c converted to be sf_logb.c. */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
13 /* float logb(float x)
14 * return the binary exponent of non-zero x
15 * logbf(0) = -inf, raise divide-by-zero floating point exception
16 * logbf(+inf|-inf) = +inf (no signal is raised)
17 * logbf(NaN) = NaN (no signal is raised)
18 * Per C99 recommendation, a NaN argument is returned unchanged.
35 if(FLT_UWORD_IS_ZERO(hx)) {
37 /* arg==0: return -inf and raise divide-by-zero exception */
38 SET_FLOAT_WORD(xx,hx); /* +0.0 */
39 return -1./xx; /* logbf(0) = -inf */
41 if(FLT_UWORD_IS_SUBNORMAL(hx)) {
42 for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
45 else if (FLT_UWORD_IS_INFINITE(hx)) return HUGE_VALF; /* x==+|-inf */
46 else if (FLT_UWORD_IS_NAN(hx)) return x;
47 else return (float) ((hx>>23)-127);
50 #ifdef _DOUBLE_IS_32BITS
59 return (double) logbf((float) x);
62 #endif /* defined(_DOUBLE_IS_32BITS) */