llrintl.c 665 B

1234567891011121314151617181920212223242526272829303132333435
  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. int e;
  19. e = fetestexcept(FE_INEXACT);
  20. x = rintl(x);
  21. if (!e && (x > LLONG_MAX || x < LLONG_MIN))
  22. feclearexcept(FE_INEXACT);
  23. /* conversion */
  24. return x;
  25. }
  26. #else
  27. long long llrintl(long double x)
  28. {
  29. return rintl(x);
  30. }
  31. #endif