1
0

llrintl.c 694 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <limits.h>
  2. #include <fenv.h>
  3. #include "libm.h"
  4. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  5. long long llrintl(long double x)
  6. {
  7. return llrint(x);
  8. }
  9. #elif defined(FE_INEXACT)
  10. /*
  11. see comments in lrint.c
  12. Note that if LLONG_MAX == 0x7fffffffffffffff && LDBL_MANT_DIG == 64
  13. then x == 2**63 - 0.5 is the only input that overflows and
  14. raises inexact (with tonearest or upward rounding mode)
  15. */
  16. long long llrintl(long double x)
  17. {
  18. #pragma STDC FENV_ACCESS ON
  19. int e;
  20. e = fetestexcept(FE_INEXACT);
  21. x = rintl(x);
  22. if (!e && (x > LLONG_MAX || x < LLONG_MIN))
  23. feclearexcept(FE_INEXACT);
  24. /* conversion */
  25. return x;
  26. }
  27. #else
  28. long long llrintl(long double x)
  29. {
  30. return rintl(x);
  31. }
  32. #endif