xref: /netbsd-src/external/lgpl3/mpc/dist/tests/tpl_gmp.c (revision 39f28e1e142c5bfb6be935a49cb55e2287fec7ea)
1 /* tpl_gmp.c --  Helper functions for mpfr data.
2 
3 Copyright (C) 2012, 2013 INRIA
4 
5 This file is part of GNU MPC.
6 
7 GNU MPC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 more details.
16 
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see http://www.gnu.org/licenses/ .
19 */
20 
21 #include "mpc-tests.h"
22 
23 void
tpl_read_mpz(mpc_datafile_context_t * datafile_context,mpz_t mpz)24 tpl_read_mpz (mpc_datafile_context_t* datafile_context, mpz_t mpz)
25 {
26    if (datafile_context->nextchar == EOF) {
27       printf ("Error: Unexpected EOF when reading mpz "
28               "in file '%s' line %lu\n",
29               datafile_context->pathname, datafile_context->line_number);
30       exit (1);
31    }
32    ungetc (datafile_context->nextchar, datafile_context->fd);
33    if (mpz_inp_str (mpz, datafile_context->fd, 0) == 0) {
34       printf ("Error: Impossible to read mpz "
35               "in file '%s' line %lu\n",
36               datafile_context->pathname, datafile_context->line_number);
37       exit (1);
38    }
39    datafile_context->nextchar = getc (datafile_context->fd);
40    tpl_skip_whitespace_comments (datafile_context);
41 }
42 
43 int
tpl_same_mpz_value(mpz_ptr z1,mpz_ptr z2)44 tpl_same_mpz_value (mpz_ptr z1, mpz_ptr z2)
45 {
46    return mpz_cmp (z1, z2) == 0;
47 }
48 
49 void
tpl_copy_mpz(mpz_ptr dest,mpz_srcptr src)50 tpl_copy_mpz (mpz_ptr dest, mpz_srcptr src)
51 {
52   mpz_set (dest, src);
53 }
54