1/* Test mp*_class unary expressions.
2
3Copyright 2001-2003 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library test suite.
6
7The GNU MP Library test suite is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 3 of the License,
10or (at your option) any later version.
11
12The GNU MP Library test suite is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
15Public License for more details.
16
17You should have received a copy of the GNU General Public License along with
18the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */
19
20#include "config.h"
21
22#include <iostream>
23
24#include "gmpxx.h"
25#include "gmp-impl.h"
26#include "tests.h"
27
28using namespace std;
29
30
31void
32check_mpz (void)
33{
34  // template <class T, class Op>
35  // __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, T>, Op> >
36  {
37    mpz_class a(1);
38    mpz_class b(+a); ASSERT_ALWAYS(b == 1);
39  }
40  {
41    mpz_class a(2);
42    mpz_class b;
43    b = -a; ASSERT_ALWAYS(b == -2);
44  }
45  {
46    mpz_class a(3);
47    mpz_class b;
48    b = ~a; ASSERT_ALWAYS(b == -4);
49  }
50
51  // template <class T, class U, class Op>
52  // __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, U>, Op> >
53  {
54    mpz_class a(1);
55    mpz_class b(-(-a)); ASSERT_ALWAYS(b == 1);
56  }
57  {
58    mpz_class a(2);
59    mpz_class b;
60    b = -(-(-a)); ASSERT_ALWAYS(b == -2);
61  }
62}
63
64void
65check_mpq (void)
66{
67  // template <class T, class Op>
68  // __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, T>, Op> >
69  {
70    mpq_class a(1);
71    mpq_class b(+a); ASSERT_ALWAYS(b == 1);
72  }
73  {
74    mpq_class a(2);
75    mpq_class b;
76    b = -a; ASSERT_ALWAYS(b == -2);
77  }
78
79  // template <class T, class U, class Op>
80  // __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, U>, Op> >
81  {
82    mpq_class a(1);
83    mpq_class b(-(-a)); ASSERT_ALWAYS(b == 1);
84  }
85  {
86    mpq_class a(2);
87    mpq_class b;
88    b = -(-(-a)); ASSERT_ALWAYS(b == -2);
89  }
90}
91
92void
93check_mpf (void)
94{
95  // template <class T, class Op>
96  // __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, T>, Op> >
97  {
98    mpf_class a(1);
99    mpf_class b(+a); ASSERT_ALWAYS(b == 1);
100  }
101  {
102    mpf_class a(2);
103    mpf_class b;
104    b = -a; ASSERT_ALWAYS(b == -2);
105  }
106
107  // template <class T, class U, class Op>
108  // __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, U>, Op> >
109  {
110    mpf_class a(1);
111    mpf_class b(-(-a)); ASSERT_ALWAYS(b == 1);
112  }
113  {
114    mpf_class a(2);
115    mpf_class b;
116    b = -(-(-a)); ASSERT_ALWAYS(b == -2);
117  }
118}
119
120
121int
122main (void)
123{
124  tests_start();
125
126  check_mpz();
127  check_mpq();
128  check_mpf();
129
130  tests_end();
131  return 0;
132}
133