This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v9 3/3] Add tests for strfrom functions
On Tue, 18 Oct 2016, Gabriel F. T. Gomes wrote:
> +/* Hexadecimal tests. */
> +static const struct htests htest[] = {
> + {"%a", { "0x1,ffp+6", "0x3,fep+5", "0x7,fcp+4", "0xf,f8p+3" },
> + {0x1.ffp+6, 0x1.ffp+6, 0x1.ffp+6}},
> + {"%a", { "0x1,88p+4", "0x3,1p+3", "0x6,2p+2", "0xc,4p+1" },
> + {0x1.88p+4, 0x1.88p+4, 0x1.88p+4}},
> + {"%A", { "-0X1,88P+5", "-0X3,1P+4", "-0X6,2P+3", "-0XC,4P+2" },
> + {-0x1.88p+5, -0x1.88p+5, -0x1.88p+5}},
> + {"%a", { "0x1,44p+10", "0x2,88p+9", "0x5,1p+8", "0xa,2p+7"},
> + {0x1.44p+10, 0x1.44p+10, 0x1.44p+10}},
> + {"%a", { "0x1p-10", "0x2p-11", "0x4p-12", "0x8p-13"},
> + {0x0.0040p+0, 0x0.0040p+0, 0x0.0040p+0}},
> + {"%a", { "0x1,4p+3", "0x2,8p+2", "0x5p+1", "0xap+0"},
> + {10.0, 10.0, 10.0}}
> +};
These still aren't type-generic.
> +/* Hexadecimal tests. */
> +static const struct htests htest[] = {
> + {"%a", { "0x1.ffp+6", "0x3.fep+5", "0x7.fcp+4", "0xf.f8p+3" },
> + {0x1.ffp+6, 0x1.ffp+6, 0x1.ffp+6}},
> + {"%a", { "0x1.88p+4", "0x3.1p+3", "0x6.2p+2", "0xc.4p+1" },
> + {0x1.88p+4, 0x1.88p+4, 0x1.88p+4}},
> + {"%A", { "-0X1.88P+5", "-0X3.1P+4", "-0X6.2P+3", "-0XC.4P+2" },
> + {-0x1.88p+5, -0x1.88p+5, -0x1.88p+5}},
> + {"%a", { "0x1.44p+10", "0x2.88p+9", "0x5.1p+8", "0xa.2p+7"},
> + {0x1.44p+10, 0x1.44p+10, 0x1.44p+10}},
> + {"%a", { "0x1p-10", "0x2p-11", "0x4p-12", "0x8p-13"},
> + {0x0.0040p+0, 0x0.0040p+0, 0x0.0040p+0}},
> + {"%a", { "0x1.4p+3", "0x2.8p+2", "0x5p+1", "0xap+0"},
> + {10.0, 10.0, 10.0}}
Likewise.
> +#define TEST(s, fmt, size, rc, f, d, ld) \
> + { \
> + s, fmt, size, rc, { ENTRY (f, d, ld) } \
> + }
You should have one argument to TEST that is the constant used for all
types (and that then gets the appropriate suffix added to it for each
type). It should not be necessary to update the tables of tests at all
when adding a new floating-point type (in general, the idea of making such
tests type-generic is so that as little as possible needs to change to
make them test a new type; ideally only the definitions of
GEN_TEST_STRTOD_FOREACH and STRTOD_TEST_FOREACH). The only obvious
differences I see between the constants in your tests for different types
is that some have more precision in the constants for double and long
double, but it's fine to have the extra digits in the float constant even
if they aren't significant to its value.
That is, the definition should look something like
{ s, fmt, size, rc, { GEN_TEST_STRTOD_FOREACH (SOMETHING, f) } }
where SOMETHING expands to concatenate its 7th argument (the
floating-point number) with its 5th (the constant suffix) (followed by a
comma). Then I think you can get rid of the ENTRY and CHOOSE macros.
(tst-strtod-round is different because it involves data for every
floating-point *format*, which then needs mapping to the supported types.)
--
Joseph S. Myers
joseph@codesourcery.com