s_logb.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #if !defined(__ppc__)
  2. /* @(#)s_logb.c 5.1 93/09/24 */
  3. /*
  4. * ====================================================
  5. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  6. *
  7. * Developed at SunPro, a Sun Microsystems, Inc. business.
  8. * Permission to use, copy, modify, and distribute this
  9. * software is freely granted, provided that this notice
  10. * is preserved.
  11. * ====================================================
  12. */
  13. #if defined(LIBM_SCCS) && !defined(lint)
  14. static char rcsid[] = "$NetBSD: s_logb.c,v 1.8 1995/05/10 20:47:50 jtc Exp $";
  15. #endif
  16. /*
  17. * double logb(x)
  18. * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
  19. * Use ilogb instead.
  20. */
  21. #include "math.h"
  22. #include "math_private.h"
  23. #ifdef __STDC__
  24. double logb(double x)
  25. #else
  26. double logb(x)
  27. double x;
  28. #endif
  29. {
  30. int32_t lx,ix;
  31. EXTRACT_WORDS(ix,lx,x);
  32. ix &= 0x7fffffff; /* high |x| */
  33. if((ix|lx)==0) return -1.0/fabs(x);
  34. if(ix>=0x7ff00000) return x*x;
  35. if((ix>>=20)==0) /* IEEE 754 logb */
  36. return -1022.0;
  37. else
  38. return (double) (ix-1023);
  39. }
  40. #endif /* !__ppc__ */