1 /* 2009 for Newlib: Sun's sf_ilogb.c converted to be sf_logb.c. */
2 /*
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 *
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
9 * is preserved.
10 * ====================================================
11 */
12
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.
19 */
20
21 #include "fdlibm.h"
22
23 float
logbf(float x)24 logbf(float x)
25 {
26 __int32_t hx,ix;
27
28 GET_FLOAT_WORD(hx,x);
29 hx &= 0x7fffffff;
30 if(FLT_UWORD_IS_ZERO(hx)) {
31 /* arg==0: return -inf and raise divide-by-zero exception */
32 return -1.f/fabsf(x); /* logbf(0) = -inf */
33 }
34 if(FLT_UWORD_IS_SUBNORMAL(hx)) {
35 for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
36 return (float) ix;
37 }
38 else if (FLT_UWORD_IS_INFINITE(hx)) return HUGE_VALF; /* x==+|-inf */
39 else if (FLT_UWORD_IS_NAN(hx)) return x + x;
40 else return (float) ((hx>>23)-127);
41 }
42
43 _MATH_ALIAS_f_f(logb)
44