1 /* Generate table of tests in tst-strtod-round.c from
3 Copyright (C) 2012 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
26 /* Work around incorrect ternary value from mpfr_strtofr
27 <https://sympa.inria.fr/sympa/arc/mpfr/2012-08/msg00005.html>. */
31 string_to_fp (mpfr_t f, const char *s, mpfr_rnd_t rnd)
35 mpfr_init2 (f2, 100000);
36 int r0 = mpfr_strtofr (f2, s, NULL, 0, rnd);
37 int r = mpfr_set (f, f2, rnd);
38 mpfr_subnormalize (f, r, rnd);
42 int r = mpfr_strtofr (f, s, NULL, 0, rnd);
43 mpfr_subnormalize (f, r, rnd);
49 print_fp (mpfr_t f, const char *suffix, const char *suffix2)
52 mpfr_printf ("\t%sINFINITY%s", mpfr_signbit (f) ? "-" : "", suffix2);
54 mpfr_printf ("\t%Ra%s%s", f, suffix, suffix2);
58 round_str (const char *s, const char *suffix,
59 int prec, int emin, int emax, bool need_exact)
62 mpfr_set_default_prec (prec);
66 int r = string_to_fp (f, s, MPFR_RNDD);
68 mpfr_printf ("\t%s,\n", r ? "false" : "true");
69 print_fp (f, suffix, ",\n");
70 string_to_fp (f, s, MPFR_RNDN);
71 print_fp (f, suffix, ",\n");
72 string_to_fp (f, s, MPFR_RNDZ);
73 print_fp (f, suffix, ",\n");
74 string_to_fp (f, s, MPFR_RNDU);
75 print_fp (f, suffix, "");
80 round_for_all (const char *s)
82 static const struct fmt {
89 { "f", 24, -148, 128, false },
90 { "", 53, -1073, 1024, false },
91 { "L", 53, -1073, 1024, false },
92 /* This is the Intel extended float format. */
93 { "L", 64, -16444, 16384, false },
94 /* This is the Motorola extended float format. */
95 { "L", 64, -16445, 16384, false },
96 { "L", 106, -1073, 1024, true },
97 { "L", 113, -16493, 16384, false },
99 mpfr_printf (" TEST (\"");
104 if ((p - s) % 60 == 59 && p[1])
105 mpfr_printf ("\"\n\t\"");
107 mpfr_printf ("\",\n");
109 for (i = 0; i < 7; i++)
111 round_str (s, formats[i].suffix, formats[i].prec,
112 formats[i].emin, formats[i].emax, formats[i].need_exact);
116 mpfr_printf ("),\n");
125 while ((nbytes = getline (&p, &len, stdin)) != -1)
127 if (p[nbytes - 1] == '\n')