tst-atof2.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. static const struct
  5. {
  6. const char *str;
  7. const char *expected;
  8. } tests[] =
  9. {
  10. { "1e308", "1e+308" },
  11. { "100000000e300", "1e+308" },
  12. { "0x1p1023", "8.98847e+307" },
  13. { "0x1000p1011", "8.98847e+307" },
  14. { "0x1p1020", "1.12356e+307" },
  15. { "0x0.00001p1040", "1.12356e+307" },
  16. { "1e-307", "1e-307" },
  17. { "0.000001e-301", "1e-307" },
  18. { "0.0000001e-300", "1e-307" },
  19. { "0.00000001e-299", "1e-307" },
  20. { "1000000e-313", "1e-307" },
  21. { "10000000e-314", "1e-307" },
  22. { "100000000e-315", "1e-307" },
  23. { "0x1p-1021", "4.45015e-308" },
  24. { "0x1000p-1033", "4.45015e-308" },
  25. { "0x10000p-1037", "4.45015e-308" },
  26. { "0x0.001p-1009", "4.45015e-308" },
  27. { "0x0.0001p-1005", "4.45015e-308" },
  28. };
  29. #define NTESTS (sizeof (tests) / sizeof (tests[0]))
  30. static int
  31. do_test (void)
  32. {
  33. int status = 0;
  34. for (int i = 0; i < NTESTS; ++i)
  35. {
  36. char buf[100];
  37. snprintf (buf, sizeof (buf), "%g", atof (tests[i].str));
  38. if (strcmp (buf, tests[i].expected) != 0)
  39. {
  40. printf ("%d: got \"%s\", expected \"%s\"\n",
  41. i, buf, tests[i].expected);
  42. status = 1;
  43. }
  44. }
  45. return status;
  46. }
  47. #define TEST_FUNCTION do_test ()
  48. #include "../test-skeleton.c"