scalbnl.c 682 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "libm.h"
  2. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  3. long double scalbnl(long double x, int n)
  4. {
  5. return scalbn(x, n);
  6. }
  7. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  8. long double scalbnl(long double x, int n)
  9. {
  10. union IEEEl2bits scale;
  11. if (n > 16383) {
  12. x *= 0x1p16383L;
  13. n -= 16383;
  14. if (n > 16383) {
  15. x *= 0x1p16383L;
  16. n -= 16383;
  17. if (n > 16383)
  18. return x * 0x1p16383L;
  19. }
  20. } else if (n < -16382) {
  21. x *= 0x1p-16382L;
  22. n += 16382;
  23. if (n < -16382) {
  24. x *= 0x1p-16382L;
  25. n += 16382;
  26. if (n < -16382)
  27. return x * 0x1p-16382L;
  28. }
  29. }
  30. scale.e = 1.0;
  31. scale.bits.exp = 0x3fff + n;
  32. return x * scale.e;
  33. }
  34. #endif