1 /*
2 test file for swap
3 
4 Copyright (C) 2012 Andreas Enge
5 
6 This file is part of the MPFRCX Library.
7 
8 The MPFRCX 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.
12 
13 The MPFRCX 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.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with the MPFRCX library; see the file COPYING.LESSER.  If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA.
22 */
23 
24 #include <stdio.h>
25 #include "mpfrcx.h"
26 
27 
main(void)28 int main (void) {
29    gmp_randstate_t state;
30    mpfrx_t f, g, fc, gc;
31    int maxdeg = 100;
32    mpfr_prec_t fprec = 213, gprec = 117;
33 
34    gmp_randinit_default (state);
35    mpfrx_init (f, maxdeg + 1, fprec);
36    mpfrx_init (g, maxdeg + 1, gprec);
37    mpfrx_urandom (f, maxdeg, state);
38    mpfrx_urandom (g, maxdeg, state);
39    mpfrx_init_set (fc, f);
40    mpfrx_init_set (gc, g);
41 
42    mpfrx_swap (f, g);
43    if (mpfrx_get_prec (f) != gprec || mpfrx_get_prec (g) != fprec) {
44       fprintf (stderr, "Error in swap: precisions not swapped correctly\n");
45       exit (1);
46    }
47    if (mpfrx_cmp (f, gc) != 0 || mpfrx_cmp (g, fc) != 0) {
48       fprintf (stderr, "Error in swap: content of variable not swapped correctly\n");
49       exit (1);
50    }
51 
52    gmp_randclear (state);
53    mpfrx_clear (f);
54    mpfrx_clear (g);
55    mpfrx_clear (fc);
56    mpfrx_clear (gc);
57 
58    return 0;
59 }
60