s_ilogbf.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* s_ilogbf.c -- float version of s_ilogb.c.
  2. * Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].
  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. #include "cdefs-compat.h"
  15. //__FBSDID("$FreeBSD: src/lib/msun/src/s_ilogbf.c,v 1.8 2008/02/22 02:30:35 das Exp $");
  16. #include <limits.h>
  17. #include "openlibm.h"
  18. #include "math_private.h"
  19. DLLEXPORT int
  20. ilogbf(float x)
  21. {
  22. int32_t hx,ix;
  23. GET_FLOAT_WORD(hx,x);
  24. hx &= 0x7fffffff;
  25. if(hx<0x00800000) {
  26. if(hx==0)
  27. return FP_ILOGB0;
  28. else /* subnormal x */
  29. for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
  30. return ix;
  31. }
  32. else if (hx<0x7f800000) return (hx>>23)-127;
  33. else if (hx>0x7f800000) return FP_ILOGBNAN;
  34. else return INT_MAX;
  35. }