1
0

s_ilogbf.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 <limits.h>
  15. #include <math.h>
  16. #include "math_private.h"
  17. int ilogbf(float x)
  18. {
  19. int32_t hx,ix;
  20. GET_FLOAT_WORD(hx,x);
  21. hx &= 0x7fffffff;
  22. if(hx<0x00800000) {
  23. if(hx==0)
  24. return FP_ILOGB0;
  25. else /* subnormal x */
  26. for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
  27. return ix;
  28. }
  29. else if (hx<0x7f800000) return (hx>>23)-127;
  30. else if (hx>0x7f800000) return FP_ILOGBNAN;
  31. else return INT_MAX;
  32. }