Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / common / sf_logb.c
blob75336a1e00ffdcffafecba4f7e50d096ecd96d16
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.
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 * ====================================================
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.
21 #include "fdlibm.h"
23 float
24 #ifdef __STDC__
25 logbf(float x)
26 #else
27 logbf(x)
28 float x;
29 #endif
31 __int32_t hx,ix;
33 GET_FLOAT_WORD(hx,x);
34 hx &= 0x7fffffff;
35 if(FLT_UWORD_IS_ZERO(hx)) {
36 float xx;
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;
43 return (float) ix;
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
52 #ifdef __STDC__
53 double logb(double x)
54 #else
55 double logb(x)
56 double x;
57 #endif
59 return (double) logbf((float) x);
62 #endif /* defined(_DOUBLE_IS_32BITS) */