Import Upstream version 0.8.2
[platform/upstream/mpc.git] / tests / tadd_fr.c
1 /* test file for mpc_add_fr.
2
3 Copyright (C) 2008 Philippe Th\'eveny, Andreas Enge
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 static void
26 check_ternary_value (mpfr_prec_t prec_max, mpfr_prec_t step)
27 {
28   mpfr_prec_t prec;
29   mpc_t z;
30   mpfr_t f;
31
32   mpc_init2 (z, 2);
33   mpfr_init (f);
34
35   for (prec = 2; prec < prec_max; prec += step)
36     {
37       mpc_set_prec (z, prec);
38       mpfr_set_prec (f, prec);
39
40       mpc_set_ui (z, 1, MPC_RNDNN);
41       mpfr_set_ui (f, 1, GMP_RNDN);
42       if (mpc_add_fr (z, z, f, MPC_RNDNZ))
43         {
44           printf ("Error in mpc_add_fr: 1+1 should be exact\n");
45           exit (1);
46         }
47
48       mpc_set_ui (z, 1, MPC_RNDNN);
49       mpc_mul_2exp (z, z, prec, MPC_RNDNN);
50       if (mpc_add_fr (z, z, f, MPC_RNDNN) == 0)
51         {
52           fprintf (stderr, "Error in mpc_add_fr: 2^prec+1 cannot be exact\n");
53           exit (1);
54         }
55     }
56   mpc_clear (z);
57   mpfr_clear (f);
58 }
59
60 int
61 main (void)
62 {
63   DECL_FUNC (CCF, f, mpc_add_fr);
64   test_start ();
65
66   check_ternary_value (1024, 1);
67
68   data_check (f, "add_fr.dat");
69   tgeneric (f, 2, 1024, 7, -1);
70
71   test_end ();
72   return 0;
73 }