Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libm/common/sf_logb.c')
-rw-r--r--newlib/libm/common/sf_logb.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/newlib/libm/common/sf_logb.c b/newlib/libm/common/sf_logb.c
index f193f91f6..75336a1e0 100644
--- a/newlib/libm/common/sf_logb.c
+++ b/newlib/libm/common/sf_logb.c
@@ -1,7 +1,4 @@
-/* sf_logb.c -- float version of s_logb.c.
- * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
- */
-
+/* 2009 for Newlib: Sun's sf_ilogb.c converted to be sf_logb.c. */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
@@ -13,24 +10,41 @@
* ====================================================
*/
+/* float logb(float x)
+ * return the binary exponent of non-zero x
+ * logbf(0) = -inf, raise divide-by-zero floating point exception
+ * logbf(+inf|-inf) = +inf (no signal is raised)
+ * logbf(NaN) = NaN (no signal is raised)
+ * Per C99 recommendation, a NaN argument is returned unchanged.
+ */
+
#include "fdlibm.h"
+float
#ifdef __STDC__
- float logbf(float x)
+logbf(float x)
#else
- float logbf(x)
- float x;
+logbf(x)
+float x;
#endif
{
- __int32_t ix;
- GET_FLOAT_WORD(ix,x);
- ix &= 0x7fffffff; /* high |x| */
- if(FLT_UWORD_IS_ZERO(ix)) return (float)-1.0/fabsf(x);
- if(!FLT_UWORD_IS_FINITE(ix)) return x*x;
- if((ix>>=23)==0) /* IEEE 754 logb */
- return -126.0;
- else
- return (float) (ix-127);
+ __int32_t hx,ix;
+
+ GET_FLOAT_WORD(hx,x);
+ hx &= 0x7fffffff;
+ if(FLT_UWORD_IS_ZERO(hx)) {
+ float xx;
+ /* arg==0: return -inf and raise divide-by-zero exception */
+ SET_FLOAT_WORD(xx,hx); /* +0.0 */
+ return -1./xx; /* logbf(0) = -inf */
+ }
+ if(FLT_UWORD_IS_SUBNORMAL(hx)) {
+ for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
+ return (float) ix;
+ }
+ else if (FLT_UWORD_IS_INFINITE(hx)) return HUGE_VALF; /* x==+|-inf */
+ else if (FLT_UWORD_IS_NAN(hx)) return x;
+ else return (float) ((hx>>23)-127);
}
#ifdef _DOUBLE_IS_32BITS