1 /* Test file for mpfr_min_prec.
3 Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 Contributed by the AriC and Caramel projects, INRIA.
6 This file is part of the GNU MPFR Library.
8 The GNU MPFR Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
13 The GNU MPFR Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
20 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
26 #include "mpfr-test.h"
29 main (int argc, char *argv[])
39 /* Check special values */
41 ret = mpfr_min_prec (x);
42 MPFR_ASSERTN (ret == 0);
45 ret = mpfr_min_prec (x);
46 MPFR_ASSERTN (ret == 0);
49 ret = mpfr_min_prec (x);
50 MPFR_ASSERTN (ret == 0);
52 mpfr_set_ui (x, 0, MPFR_RNDN);
53 ret = mpfr_min_prec (x);
54 MPFR_ASSERTN (ret == 0);
58 mpfr_set_ui (x, 1, MPFR_RNDN);
59 ret = mpfr_min_prec (x);
60 MPFR_ASSERTN (ret == 1);
62 mpfr_set_ui (x, 17, MPFR_RNDN);
63 ret = mpfr_min_prec (x);
64 MPFR_ASSERTN (ret == 5);
66 mpfr_set_ui (x, 42, MPFR_RNDN);
67 ret = mpfr_min_prec (x);
68 MPFR_ASSERTN (ret == 5);
70 mpfr_set_prec (x, 256);
71 for (i = 0; i <= 255; i++)
73 mpfr_set_ui_2exp (x, 1, i, MPFR_RNDN);
74 mpfr_add_ui (x, x, 1, MPFR_RNDN);
75 ret = mpfr_min_prec (x);
78 printf ("Error for x = 2^%lu + 1\n", i);
79 printf ("Expected %lu, got %lu\n", i + 1, (unsigned long) ret);
84 for (i = MPFR_PREC_MIN; i <= 255; i++)
87 mpfr_set_ui_2exp (x, 1, i, MPFR_RNDN);
88 mpfr_sub_ui (x, x, 1, MPFR_RNDN);
89 ret = mpfr_min_prec (x);
92 printf ("Error for x = 2^%lu - 1\n", i);
93 printf ("Expected %lu, got %lu\n", i, (unsigned long) ret);