lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | |
| 4 | struct |
| 5 | { |
| 6 | long double val; |
| 7 | const char str[4][7]; |
| 8 | } tests[] = |
| 9 | { |
| 10 | { 0x0.FFFFp+0L, { "0X1P+0", "0X2P-1", "0X4P-2", "0X8P-3" } }, |
| 11 | { 0x0.FFFFp+1L, { "0X1P+1", "0X2P+0", "0X4P-1", "0X8P-2" } }, |
| 12 | { 0x0.FFFFp+2L, { "0X1P+2", "0X2P+1", "0X4P+0", "0X8P-1" } }, |
| 13 | { 0x0.FFFFp+3L, { "0X1P+3", "0X2P+2", "0X4P+1", "0X8P+0" } } |
| 14 | }; |
| 15 | |
| 16 | static int |
| 17 | do_test (void) |
| 18 | { |
| 19 | char buf[100]; |
| 20 | int ret = 0; |
| 21 | |
| 22 | for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i) |
| 23 | { |
| 24 | snprintf (buf, sizeof (buf), "%.0LA", tests[i].val); |
| 25 | |
| 26 | size_t j; |
| 27 | for (j = 0; j < 4; ++j) |
| 28 | if (strcmp (buf, tests[i].str[j]) == 0) |
| 29 | break; |
| 30 | |
| 31 | if (j == 4) |
| 32 | { |
| 33 | printf ("%zd: got \"%s\", expected \"%s\" or equivalent\n", |
| 34 | i, buf, tests[i].str[0]); |
| 35 | ret = 1; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | return ret; |
| 40 | } |
| 41 | |
| 42 | #define TEST_FUNCTION do_test () |
| 43 | #include "../test-skeleton.c" |