5ae2e28d7a727146e630c25d2097d2e09b2c00b0
[platform/upstream/mpc.git] / tests / tprec.c
1 /* tprec.c -- Test file for mpc_set_prec, mpc_get_prec and mpc_get_prec2.
2
3 Copyright (C) 2009 Philippe Th\'eveny
4
5 This file is part of the MPC Library.
6
7 The MPC Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or (at your
10 option) any later version.
11
12 The MPC Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with the MPC Library; see the file COPYING.LIB.  If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 MA 02111-1307, USA. */
21
22 #include <stdlib.h>
23 #include "mpc-tests.h"
24
25 int
26 main (void)
27 {
28   mpc_t z;
29   mp_prec_t prec, pr, pi;
30
31   mpc_init2 (z, 1000);
32
33   for (prec = 2; prec <= 1000; prec++)
34     {
35       /* check set_prec/get_prec */
36       mpfr_set_prec (MPC_RE (z), prec);
37       mpfr_set_prec (MPC_IM (z), prec + 1);
38       if (mpc_get_prec (z) != 0)
39         {
40           printf ("Error in mpc_get_prec for prec (re) = %lu, "
41                   "prec (im) = %lu\n", (unsigned long int) prec,
42                   (unsigned long int) prec + 1ul);
43
44           exit (1);
45         }
46
47       mpc_get_prec2 (&pr, &pi, z);
48       if (pr != prec || pi != prec + 1)
49         {
50           printf ("Error in mpc_get_prec2 for prec (re) = %lu, "
51                   "prec (im) = %lu\n", (unsigned long int) prec,
52                   (unsigned long int) prec + 1ul);
53
54           exit (1);
55         }
56
57       mpc_set_prec (z, prec);
58       if (mpc_get_prec (z) != prec)
59         {
60           printf ("Error in mpc_get_prec for prec = %lu\n",
61                   (unsigned long int) prec);
62
63           exit (1);
64         }
65     }
66
67   mpc_clear (z);
68
69   return 0;
70 }