1 /*
2 test file for neg
3
4 Copyright (C) 2009, 2010 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
error(mpcx_t h,mpcx_t f)28 static void error (mpcx_t h, mpcx_t f) {
29 fprintf (stderr, "Error in neg: -(-f) yields h with\nf: ");
30 mpcx_out_str (stderr, 16, 0, f);
31 fprintf (stderr, "\nh: ");
32 mpcx_out_str (stderr, 16, 0, h);
33 fprintf (stderr, "\n");
34 exit (1);
35 }
36
37
check_neg(mpcx_t f)38 static void check_neg (mpcx_t f) {
39 mpcx_t h;
40
41 mpcx_init (h, 10, mpcx_get_prec (f));
42
43 mpcx_neg (h, f);
44 mpcx_neg (h, h);
45 if (mpcx_cmp (h, f))
46 error (h, f);
47
48 mpcx_clear (h);
49 }
50
51
check_neg_random(gmp_randstate_t state)52 static void check_neg_random (gmp_randstate_t state) {
53 int deg;
54 mpcx_t f;
55
56 mpcx_init (f, 10, 103);
57
58 for (deg = -1; deg <= 100; deg++) {
59 mpcx_urandom (f, deg, state);
60 check_neg (f);
61 }
62
63 mpcx_clear (f);
64 }
65
66
main(void)67 int main (void) {
68 gmp_randstate_t state;
69
70 gmp_randinit_default (state);
71
72 check_neg_random (state);
73
74 gmp_randclear (state);
75
76 return 0;
77 }
78