rint.c 745 B

123456789101112131415161718192021222324252627282930313233
  1. #include <math.h>
  2. #include <float.h>
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #include <stdio.h>
  6. #define check_d1(func, param, expected) \
  7. do { \
  8. int err; hex_union ur; hex_union up; \
  9. double result = func(param); up.f = param; ur.f = result; \
  10. errors += (err = (result != (expected))); \
  11. err \
  12. ? printf("FAIL: %s(%g/"HEXFMT")=%g/"HEXFMT" (expected %g)\n", \
  13. #func, (double)(param), (long long)up.hex, result, (long long)ur.hex, (double)(expected)) \
  14. : printf("PASS: %s(%g)=%g\n", #func, (double)(param), result); \
  15. } while (0)
  16. #define HEXFMT "%08llx"
  17. typedef union {
  18. double f;
  19. uint64_t hex;
  20. } hex_union;
  21. double result;
  22. int errors = 0;
  23. int main(void)
  24. {
  25. check_d1(rint, 0.6, 1.0);
  26. printf("Errors: %d\n", errors);
  27. return errors;
  28. }