1 /* Test mp*_class unary expressions.
2
3 Copyright 2001-2003 Free Software Foundation, Inc.
4
5 This file is part of the GNU MP Library test suite.
6
7 The GNU MP Library test suite is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 3 of the License,
10 or (at your option) any later version.
11
12 The GNU MP Library test suite is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15 Public License for more details.
16
17 You should have received a copy of the GNU General Public License along with
18 the 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
28 using namespace std;
29
30
31 void
check_mpz(void)32 check_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
64 void
check_mpq(void)65 check_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
92 void
check_mpf(void)93 check_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
121 int
main(void)122 main (void)
123 {
124 tests_start();
125
126 check_mpz();
127 check_mpq();
128 check_mpf();
129
130 tests_end();
131 return 0;
132 }
133