s_logbf.c 1005 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* s_logbf.c -- float version of s_logb.c.
  2. * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  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 <sys/cdefs.h>
  15. #include "openlibm.h"
  16. #include "math_private.h"
  17. static const float
  18. two25 = 3.355443200e+07; /* 0x4c000000 */
  19. float
  20. logbf(float x)
  21. {
  22. int32_t ix;
  23. GET_FLOAT_WORD(ix,x);
  24. ix &= 0x7fffffff; /* high |x| */
  25. if(ix==0) return (float)-1.0/fabsf(x);
  26. if(ix>=0x7f800000) return x*x;
  27. if(ix<0x00800000) {
  28. x *= two25; /* convert subnormal x to normal */
  29. GET_FLOAT_WORD(ix,x);
  30. ix &= 0x7fffffff;
  31. return (float) ((ix>>23)-127-25);
  32. } else
  33. return (float) ((ix>>23)-127);
  34. }