2017-11-02 19:14:51 +08:00
|
|
|
#include <array_length.h>
|
2006-08-03 17:36:43 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2006-08-08 23:51:48 +08:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
long double val;
|
|
|
|
const char str[4][7];
|
|
|
|
} tests[] =
|
|
|
|
{
|
|
|
|
{ 0x0.FFFFp+0L, { "0X1P+0", "0X2P-1", "0X4P-2", "0X8P-3" } },
|
|
|
|
{ 0x0.FFFFp+1L, { "0X1P+1", "0X2P+0", "0X4P-1", "0X8P-2" } },
|
|
|
|
{ 0x0.FFFFp+2L, { "0X1P+2", "0X2P+1", "0X4P+0", "0X8P-1" } },
|
|
|
|
{ 0x0.FFFFp+3L, { "0X1P+3", "0X2P+2", "0X4P+1", "0X8P+0" } }
|
|
|
|
};
|
|
|
|
|
2006-08-03 17:36:43 +08:00
|
|
|
static int
|
|
|
|
do_test (void)
|
|
|
|
{
|
|
|
|
char buf[100];
|
2006-08-08 23:51:48 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
2017-11-02 19:14:51 +08:00
|
|
|
for (size_t i = 0; i < array_length (tests); ++i)
|
2013-06-06 04:44:03 +08:00
|
|
|
{
|
2006-08-08 23:51:48 +08:00
|
|
|
snprintf (buf, sizeof (buf), "%.0LA", tests[i].val);
|
|
|
|
|
|
|
|
size_t j;
|
|
|
|
for (j = 0; j < 4; ++j)
|
|
|
|
if (strcmp (buf, tests[i].str[j]) == 0)
|
|
|
|
break;
|
2006-08-03 17:36:43 +08:00
|
|
|
|
2006-08-08 23:51:48 +08:00
|
|
|
if (j == 4)
|
|
|
|
{
|
|
|
|
printf ("%zd: got \"%s\", expected \"%s\" or equivalent\n",
|
|
|
|
i, buf, tests[i].str[0]);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2006-08-03 17:36:43 +08:00
|
|
|
}
|
|
|
|
|
2006-08-08 23:51:48 +08:00
|
|
|
return ret;
|
2006-08-03 17:36:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
|
|
#include "../test-skeleton.c"
|