1 /* Test file for mpfr_frexp.
3 Copyright 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. */
23 #include <stdlib.h> /* for exit */
24 #include "mpfr-test.h"
37 inex = mpfr_frexp (&exp, y, x, MPFR_RNDN);
38 if (mpfr_nan_p (y) == 0 || inex != 0)
40 printf ("Error for mpfr_frexp(NaN)\n");
45 inex = mpfr_frexp (&exp, y, x, MPFR_RNDN);
46 if (mpfr_inf_p (y) == 0 || mpfr_sgn (y) <= 0 || inex != 0)
48 printf ("Error for mpfr_frexp(+Inf)\n");
53 inex = mpfr_frexp (&exp, y, x, MPFR_RNDN);
54 if (mpfr_inf_p (y) == 0 || mpfr_sgn (y) >= 0 || inex != 0)
56 printf ("Error for mpfr_frexp(-Inf)\n");
61 inex = mpfr_frexp (&exp, y, x, MPFR_RNDN);
62 if (mpfr_zero_p (y) == 0 || mpfr_signbit (y) != 0 || inex != 0 || exp != 0)
64 printf ("Error for mpfr_frexp(+0)\n");
68 mpfr_set_zero (x, -1);
69 inex = mpfr_frexp (&exp, y, x, MPFR_RNDN);
70 if (mpfr_zero_p (y) == 0 || mpfr_signbit (y) == 0 || inex != 0 || exp != 0)
72 printf ("Error for mpfr_frexp(-0)\n");
76 mpfr_set_ui (x, 17, MPFR_RNDN);
77 inex = mpfr_frexp (&exp, y, x, MPFR_RNDN);
79 if (mpfr_cmp_ui_2exp (y, 17, -5) != 0 || inex != 0 || exp != 5)
81 printf ("Error for mpfr_frexp(17)\n");
85 mpfr_set_si (x, -17, MPFR_RNDN);
86 inex = mpfr_frexp (&exp, y, x, MPFR_RNDN);
87 if (mpfr_cmp_si_2exp (y, -17, -5) != 0 || inex != 0 || exp != 5)
89 printf ("Error for mpfr_frexp(-17)\n");
93 /* now reduce the precision of y */
95 mpfr_set_ui (x, 17, MPFR_RNDN);
96 inex = mpfr_frexp (&exp, y, x, MPFR_RNDN);
98 if (mpfr_cmp_ui_2exp (y, 16, -5) != 0 || inex >= 0 || exp != 5)
100 printf ("Error for mpfr_frexp(17) with prec=4, RNDN\n");
104 mpfr_set_ui (x, 17, MPFR_RNDN);
105 inex = mpfr_frexp (&exp, y, x, MPFR_RNDZ);
106 if (mpfr_cmp_ui_2exp (y, 16, -5) != 0 || inex >= 0 || exp != 5)
108 printf ("Error for mpfr_frexp(17) with prec=4, RNDZ\n");
112 mpfr_set_ui (x, 17, MPFR_RNDN);
113 inex = mpfr_frexp (&exp, y, x, MPFR_RNDD);
114 if (mpfr_cmp_ui_2exp (y, 16, -5) != 0 || inex >= 0 || exp != 5)
116 printf ("Error for mpfr_frexp(17) with prec=4, RNDD\n");
120 mpfr_set_ui (x, 17, MPFR_RNDN);
121 inex = mpfr_frexp (&exp, y, x, MPFR_RNDU);
122 if (mpfr_cmp_ui_2exp (y, 18, -5) != 0 || inex <= 0 || exp != 5)
124 printf ("Error for mpfr_frexp(17) with prec=4, RNDU\n");
133 main (int argc, char *argv[])