frexpl.c 588 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <math.h>
  2. #include <stdint.h>
  3. #include <float.h>
  4. #if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  5. /* This version is for 80-bit little endian long double */
  6. long double frexpl(long double x, int *e)
  7. {
  8. union { long double ld; uint16_t hw[5]; } y = { x };
  9. int ee = y.hw[4]&0x7fff;
  10. if (!ee) {
  11. if (x) {
  12. x = frexpl(x*0x1p64, e);
  13. *e -= 64;
  14. } else *e = 0;
  15. return x;
  16. } else if (ee == 0x7fff) {
  17. return x;
  18. }
  19. *e = ee - 0x3ffe;
  20. y.hw[4] &= 0x8000;
  21. y.hw[4] |= 0x3ffe;
  22. return y.ld;
  23. }
  24. #else
  25. long double frexpl(long double x, int *e)
  26. {
  27. return frexp(x, e);
  28. }
  29. #endif