mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-08 14:20:07 +00:00
Refactor tst-strtod-round.c
This file is partially generated. To make updates a little simpler, I have moved the generated code into a partially contained header to simplify regeneration. gen-tst-strtod-round.c now takes two, mandatory arguments. These arguments specify the input test data and the output destination, respectively.
This commit is contained in:
parent
078d1cf8ac
commit
118fbf0e1c
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
||||
2016-05-24 Paul E. Murphy <murphyp@linux.vnet.ibm.com>
|
||||
|
||||
* stdlib/gen-tst-strtod-round.c (main):
|
||||
Change usage to more closely match the generated
|
||||
output. Add usage and compilation instructions.
|
||||
(string_to_fp): Add and use FILE* parameter as
|
||||
output target.
|
||||
(print_fp): Likewise.
|
||||
(round_str): Likewise.
|
||||
(round_for_all): Likewise.
|
||||
* stdlib/tst-strtod-round.c (tests): Move into
|
||||
* stdlib/tst-strtod-round-data.h: New file.
|
||||
|
||||
2016-05-24 Joseph Myers <joseph@codesourcery.com>
|
||||
|
||||
[BZ #15479]
|
||||
|
@ -17,11 +17,25 @@
|
||||
License along with the GNU C Library; if not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Compile this program as:
|
||||
|
||||
gcc -std=gnu11 -O2 -Wall -Wextra gen-tst-strtod-round.c -lmpfr
|
||||
-o gen-tst-strtod-round
|
||||
|
||||
(use of current MPFR version recommended) and run it as:
|
||||
|
||||
gen-tst-strtod-round tst-strtod-round-data tst-strtod-round-data.h
|
||||
|
||||
The output file will be generated as tst-strtod-round-data.h
|
||||
*/
|
||||
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <mpfr.h>
|
||||
|
||||
/* Work around incorrect ternary value from mpfr_strtofr
|
||||
@ -47,16 +61,17 @@ string_to_fp (mpfr_t f, const char *s, mpfr_rnd_t rnd)
|
||||
}
|
||||
|
||||
static void
|
||||
print_fp (mpfr_t f, const char *suffix, const char *suffix2)
|
||||
print_fp (FILE *fout, mpfr_t f, const char *suffix, const char *suffix2)
|
||||
{
|
||||
if (mpfr_inf_p (f))
|
||||
mpfr_printf ("\t%sINFINITY%s", mpfr_signbit (f) ? "-" : "", suffix2);
|
||||
mpfr_fprintf (fout, "\t%sINFINITY%s", mpfr_signbit (f) ? "-" : "",
|
||||
suffix2);
|
||||
else
|
||||
mpfr_printf ("\t%Ra%s%s", f, suffix, suffix2);
|
||||
mpfr_fprintf (fout, "\t%Ra%s%s", f, suffix, suffix2);
|
||||
}
|
||||
|
||||
static void
|
||||
round_str (const char *s, const char *suffix,
|
||||
round_str (FILE *fout, const char *s, const char *suffix,
|
||||
int prec, int emin, int emax, bool ibm_ld)
|
||||
{
|
||||
mpfr_t f;
|
||||
@ -78,19 +93,19 @@ round_str (const char *s, const char *suffix,
|
||||
r = 1;
|
||||
mpfr_clear (max_value);
|
||||
}
|
||||
mpfr_printf ("\t%s,\n", r ? "false" : "true");
|
||||
print_fp (f, suffix, ",\n");
|
||||
mpfr_fprintf (fout, "\t%s,\n", r ? "false" : "true");
|
||||
print_fp (fout, f, suffix, ",\n");
|
||||
string_to_fp (f, s, MPFR_RNDN);
|
||||
print_fp (f, suffix, ",\n");
|
||||
print_fp (fout, f, suffix, ",\n");
|
||||
string_to_fp (f, s, MPFR_RNDZ);
|
||||
print_fp (f, suffix, ",\n");
|
||||
print_fp (fout, f, suffix, ",\n");
|
||||
string_to_fp (f, s, MPFR_RNDU);
|
||||
print_fp (f, suffix, "");
|
||||
print_fp (fout, f, suffix, "");
|
||||
mpfr_clear (f);
|
||||
}
|
||||
|
||||
static void
|
||||
round_for_all (const char *s)
|
||||
round_for_all (FILE *fout, const char *s)
|
||||
{
|
||||
static const struct fmt {
|
||||
const char *suffix;
|
||||
@ -109,39 +124,70 @@ round_for_all (const char *s)
|
||||
{ "L", 106, -1073, 1024, true },
|
||||
{ "L", 113, -16493, 16384, false },
|
||||
};
|
||||
mpfr_printf (" TEST (\"");
|
||||
mpfr_fprintf (fout, " TEST (\"");
|
||||
const char *p;
|
||||
for (p = s; *p; p++)
|
||||
{
|
||||
putchar (*p);
|
||||
fputc (*p, fout);
|
||||
if ((p - s) % 60 == 59 && p[1])
|
||||
mpfr_printf ("\"\n\t\"");
|
||||
mpfr_fprintf (fout, "\"\n\t\"");
|
||||
}
|
||||
mpfr_printf ("\",\n");
|
||||
mpfr_fprintf (fout, "\",\n");
|
||||
int i;
|
||||
for (i = 0; i < 7; i++)
|
||||
{
|
||||
round_str (s, formats[i].suffix, formats[i].prec,
|
||||
round_str (fout, s, formats[i].suffix, formats[i].prec,
|
||||
formats[i].emin, formats[i].emax, formats[i].ibm_ld);
|
||||
if (i < 6)
|
||||
mpfr_printf (",\n");
|
||||
mpfr_fprintf (fout, ",\n");
|
||||
}
|
||||
mpfr_printf ("),\n");
|
||||
mpfr_fprintf (fout, "),\n");
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
char *p = NULL;
|
||||
size_t len;
|
||||
ssize_t nbytes;
|
||||
while ((nbytes = getline (&p, &len, stdin)) != -1)
|
||||
FILE *fin, *fout;
|
||||
char *fin_name, *fout_name;
|
||||
|
||||
if (argc < 3)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s <input> <output>\n", basename (argv[0]));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fin_name = argv[1];
|
||||
fout_name = argv[2];
|
||||
|
||||
fin = fopen (fin_name, "r");
|
||||
if (fin == NULL)
|
||||
{
|
||||
perror ("Could not open input for reading");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fout = fopen (fout_name, "w");
|
||||
if (fout == NULL)
|
||||
{
|
||||
perror ("Could not open output for writing");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fprintf (fout, "/* This file was generated by %s from %s. */\n",
|
||||
__FILE__, fin_name);
|
||||
fputs ("static const struct test tests[] = {\n", fout);
|
||||
while ((nbytes = getline (&p, &len, fin)) != -1)
|
||||
{
|
||||
if (p[nbytes - 1] == '\n')
|
||||
p[nbytes - 1] = 0;
|
||||
round_for_all (p);
|
||||
round_for_all (fout, p);
|
||||
free (p);
|
||||
p = NULL;
|
||||
}
|
||||
return 0;
|
||||
fputs ("};\n", fout);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
12334
stdlib/tst-strtod-round-data.h
Normal file
12334
stdlib/tst-strtod-round-data.h
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user