tst-strtod6.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "tst-strtod.h"
  6. #define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
  7. static int \
  8. test_strto ## FSUF (const char str[]) \
  9. { \
  10. char *endp; \
  11. int result = 0; \
  12. puts (str); \
  13. FTYPE d = strto ## FSUF (str, &endp); \
  14. if (!isnan (d)) \
  15. { \
  16. puts ("strto" #FSUF " did not return NAN"); \
  17. result = 1; \
  18. } \
  19. if (issignaling (d)) \
  20. { \
  21. puts ("strto" #FSUF " returned a sNAN"); \
  22. result = 1; \
  23. } \
  24. if (strcmp (endp, "something") != 0) \
  25. { \
  26. puts ("strto" #FSUF " set incorrect end pointer"); \
  27. result = 1; \
  28. } \
  29. return result; \
  30. }
  31. GEN_TEST_STRTOD_FOREACH (TEST_STRTOD);
  32. static int
  33. do_test (void)
  34. {
  35. int result = 0;
  36. result |= STRTOD_TEST_FOREACH (test_strto, "NaN(blabla)something");
  37. result |= STRTOD_TEST_FOREACH (test_strto, "NaN(1234)something");
  38. /* UINT32_MAX. */
  39. result |= STRTOD_TEST_FOREACH (test_strto, "NaN(4294967295)something");
  40. /* UINT64_MAX. */
  41. result |= STRTOD_TEST_FOREACH (test_strto,
  42. "NaN(18446744073709551615)something");
  43. /* The case of zero is special in that "something" has to be done to make the
  44. mantissa different from zero, which would mean infinity instead of
  45. NaN. */
  46. result |= STRTOD_TEST_FOREACH (test_strto, "NaN(0)something");
  47. return result;
  48. }
  49. #define TEST_FUNCTION do_test ()
  50. #include "../test-skeleton.c"