1 /* tget_swap.c -- Test mpfi_swap.
2 
3 Copyright 2010,
4                      Spaces project, Inria Lorraine
5                      and Salsa project, INRIA Rocquencourt,
6                      and Arenaire project, Inria Rhone-Alpes, France
7                      and Lab. ANO, USTL (Univ. of Lille),  France
8 
9 
10 This file is part of the MPFI Library.
11 
12 The MPFI Library is free software; you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as published by
14 the Free Software Foundation; either version 2.1 of the License, or (at your
15 option) any later version.
16 
17 The MPFI Library is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
20 License for more details.
21 
22 You should have received a copy of the GNU Lesser General Public License
23 along with the MPFI Library; see the file COPYING.LIB.  If not, write to
24 the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25 MA 02110-1301, USA. */
26 
27 #include "mpfi-tests.h"
28 
29 int
main(int argc,char ** argv)30 main (int argc, char **argv)
31 {
32   mpfi_t a, b;
33   unsigned long pa, pb;
34 
35   mpfi_init2 (a, 53);
36   mpfi_init2 (b, 2);
37 
38   mpfr_set_ui (&(a->left), 4, MPFI_RNDD);
39   mpfr_set_ui (&(a->right), 7, MPFI_RNDU);
40   mpfr_set_ui (&(b->left), 0, MPFI_RNDD);
41   mpfr_set_ui (&(b->right), 2, MPFI_RNDU);
42   mpfi_swap (a, b);
43   if (mpfr_cmp_ui (&(b->left), 4) != 0
44       || mpfr_cmp_ui (&(b->right), 7) != 0
45       || mpfr_cmp_ui (&(a->left), 0) != 0
46       || mpfr_cmp_ui (&(a->right), 2) != 0) {
47     printf ("Error: mpfi_swap (a, b) does not swap values.\na = ");
48     mpfi_out_str (stdout, 10, 0, a);
49     printf ("\nb = ");
50     mpfi_out_str (stdout, 10, 0, b);
51     printf ("\n");
52     exit (1);
53   }
54   if (mpfi_get_prec (a) != 2 || mpfi_get_prec (b) != 53) {
55     pa = mpfi_get_prec (a);
56     pb = mpfi_get_prec (b);
57     printf ("Error: mpfi_swap(a, b) does not swap precisions.\n"
58             "precision of a = %lu\nprecision of b = %lu", pa, pb);
59     exit (1);
60   }
61 
62   mpfi_clear (a);
63   mpfi_clear (b);
64   return 0;
65 }
66