3 Copyright 2012, 2013 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library test suite.
7 The GNU MP Library test suite is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 3 of the License,
10 or (at your option) any later version.
12 The GNU MP Library test suite is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15 Public License for more details.
17 You should have received a copy of the GNU General Public License along with
18 the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
26 #include "testutils.h"
28 #define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
41 { M_PI*1e15, "b29430a256d21" },
42 { -M_PI*1e15, "-b29430a256d21" },
44 27317946752402834684213355569799764242877450894307478200123392 */
45 {0.2731794675240283468421335556979976424288e62,
46 "1100000000000000000000000000000000000000000000000000" },
51 testmain (int argc, char **argv)
56 for (i = 0; values[i].s; i++)
59 mpz_init_set_d (x, values[i].d);
60 s = mpz_get_str (NULL, 16, x);
61 if (strcmp (s, values[i].s) != 0)
63 fprintf (stderr, "mpz_set_d failed:\n"
67 values[i].d, s, values[i].s);
76 for (i = 0; i < COUNT; i++)
78 /* Use volatile, to avoid extended precision in floating point
79 registers, e.g., on m68k and 80387. */
84 mini_rrandomb (x, GMP_LIMB_BITS);
87 e = mpz_get_ui (x) - 100;
89 d = ldexp ((double) m, e);
94 fprintf (stderr, "mpz_set_d/mpz_get_d failed:\n");
97 if ((f == d) ? (mpz_cmp_d (x, d) != 0) : (mpz_cmp_d (x, d) >= 0))
99 fprintf (stderr, "mpz_cmp_d (x, d) failed:\n");
103 if (f > d && ! (mpz_cmp_d (x, f) < 0))
105 fprintf (stderr, "mpz_cmp_d (x, f) failed:\n");
115 fprintf (stderr, "mpz_set_d/mpz_get_d failed:\n");
118 fprintf (stderr, "m = %lx, e = %i\n", m, e);
119 fprintf (stderr, "d = %.15g\n", d);
120 fprintf (stderr, "f = %.15g\n", f);
121 fprintf (stderr, "f - d = %.5g\n", f - d);
124 if ((f == d) ? (mpz_cmp_d (x, d) != 0) : (mpz_cmp_d (x, d) <= 0))
126 fprintf (stderr, "mpz_cmp_d (x, d) failed:\n");
130 if (f < d && ! (mpz_cmp_d (x, f) > 0))
132 fprintf (stderr, "mpz_cmp_d (x, f) failed:\n");