s_ldexp.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*******************************************************************************
  2. * *
  3. * File frexpldexp.c, *
  4. * Functions frexp(x) and ldexp(x), *
  5. * Implementation of frexp and ldexp functions for the PowerPC. *
  6. * *
  7. * Copyright © 1991 Apple Computer, Inc. All rights reserved. *
  8. * *
  9. * Written by Ali Sazegari, started on January 1991, *
  10. * *
  11. * W A R N I N G: This routine expects a 64 bit double model. *
  12. * *
  13. * December03 1992: first rs6000 implementation. *
  14. * October 05 1993: added special cases for NaN and ° in frexp. *
  15. * May 27 1997: improved the performance of frexp by eliminating the *
  16. * switch statement. *
  17. * June 13 2001: (ram) rewrote frexp to eliminate calls to scalb and *
  18. * logb. *
  19. * *
  20. *******************************************************************************/
  21. #include <limits.h>
  22. #include <math.h>
  23. #include <endian.h>
  24. typedef union
  25. {
  26. struct {
  27. #if (__BYTE_ORDER == __BIG_ENDIAN)
  28. unsigned long int hi;
  29. unsigned long int lo;
  30. #else
  31. unsigned long int lo;
  32. unsigned long int hi;
  33. #endif
  34. } words;
  35. double dbl;
  36. } DblInHex;
  37. libm_hidden_proto(ldexp)
  38. double ldexp ( double value, int exp )
  39. {
  40. if ( exp > SHRT_MAX )
  41. exp = SHRT_MAX;
  42. else if ( exp < -SHRT_MAX )
  43. exp = -SHRT_MAX;
  44. return scalb ( value, exp );
  45. }
  46. libm_hidden_def(ldexp)