s_logb.c 829 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * ====================================================
  3. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4. *
  5. * Developed at SunPro, a Sun Microsystems, Inc. business.
  6. * Permission to use, copy, modify, and distribute this
  7. * software is freely granted, provided that this notice
  8. * is preserved.
  9. * ====================================================
  10. */
  11. /*
  12. * double logb(x)
  13. * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
  14. * Use ilogb instead.
  15. */
  16. #include "math.h"
  17. #include "math_private.h"
  18. double logb(double x)
  19. {
  20. int32_t lx,ix;
  21. EXTRACT_WORDS(ix,lx,x);
  22. ix &= 0x7fffffff; /* high |x| */
  23. if((ix|lx)==0) return -1.0/fabs(x);
  24. if(ix>=0x7ff00000) return x*x;
  25. if((ix>>=20)==0) /* IEEE 754 logb */
  26. return -1022.0;
  27. else
  28. return (double) (ix-1023);
  29. }
  30. libm_hidden_def(logb)