]> www.ginac.de Git - cln.git/blob - src/integer/ring/cl_I_ring.cc
Fix linking problems on some platforms caused by inline/non-inline versions
[cln.git] / src / integer / ring / cl_I_ring.cc
1 // Ring of integers.
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 CL_PROVIDE(cl_I_ring)
7
8 // Specification.
9 #include "cln/integer_ring.h"
10
11
12 // Implementation.
13
14 #include "cln/integer.h"
15 #include "cln/integer_io.h"
16 #define zerop zerop_inline
17 #include "cl_I.h"
18 #undef zerop
19
20 namespace cln {
21
22 static void I_fprint (cl_heap_ring* R, std::ostream& stream, const _cl_ring_element& x)
23 {
24         unused R;
25         fprint(stream,The(cl_I)(x));
26 }
27
28 static bool I_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
29 {
30         unused R;
31         return equal(The(cl_I)(x),The(cl_I)(y));
32 }
33
34 static const _cl_ring_element I_zero (cl_heap_ring* R)
35 {
36         return _cl_ring_element(R, (cl_I)0);
37 }
38
39 static bool CL_FLATTEN I_zerop (cl_heap_ring* R, const _cl_ring_element& x)
40 {
41         unused R;
42         return zerop_inline(The(cl_I)(x));
43 }
44
45 static const _cl_ring_element I_plus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
46 {
47         return _cl_ring_element(R, The(cl_I)(x) + The(cl_I)(y));
48 }
49
50 static const _cl_ring_element I_minus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
51 {
52         return _cl_ring_element(R, The(cl_I)(x) - The(cl_I)(y));
53 }
54
55 static const _cl_ring_element I_uminus (cl_heap_ring* R, const _cl_ring_element& x)
56 {
57         return _cl_ring_element(R, - The(cl_I)(x));
58 }
59
60 static const _cl_ring_element I_one (cl_heap_ring* R)
61 {
62         return _cl_ring_element(R, (cl_I)1);
63 }
64
65 static const _cl_ring_element I_canonhom (cl_heap_ring* R, const cl_I& x)
66 {
67         return _cl_ring_element(R, (cl_I)x);
68 }
69
70 static const _cl_ring_element I_mul (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
71 {
72         return _cl_ring_element(R, The(cl_I)(x) * The(cl_I)(y));
73 }
74
75 static const _cl_ring_element I_square (cl_heap_ring* R, const _cl_ring_element& x)
76 {
77         return _cl_ring_element(R, square(The(cl_I)(x)));
78 }
79
80 static const _cl_ring_element I_expt_pos (cl_heap_ring* R, const _cl_ring_element& x, const cl_I& y)
81 {
82         return _cl_ring_element(R, expt_pos(The(cl_I)(x),y));
83 }
84
85 static bool cl_I_p (const cl_number& x)
86 {
87         return (!x.pointer_p()
88                 ? x.nonpointer_tag() == cl_FN_tag
89                 : x.pointer_type() == &cl_class_bignum);
90 }
91
92 static cl_ring_setops I_setops = {
93         I_fprint,
94         I_equal
95 };
96 static cl_ring_addops I_addops = {
97         I_zero,
98         I_zerop,
99         I_plus,
100         I_minus,
101         I_uminus
102 };
103 static cl_ring_mulops I_mulops = {
104         I_one,
105         I_canonhom,
106         I_mul,
107         I_square,
108         I_expt_pos
109 };
110
111 static cl_number_ring_ops<cl_I> I_ops = {
112         cl_I_p,
113         equal,
114         zerop,
115         operator+,
116         operator-,
117         operator-,
118         operator*,
119         square,
120         expt_pos
121 };
122
123 class cl_heap_integer_ring : public cl_heap_number_ring {
124         SUBCLASS_cl_heap_ring()
125 public:
126         // Constructor.
127         cl_heap_integer_ring ()
128                 : cl_heap_number_ring (&I_setops,&I_addops,&I_mulops,
129                                        (cl_number_ring_ops<cl_number>*) &I_ops)
130                 { type = &cl_class_integer_ring; }
131         // Destructor.
132         ~cl_heap_integer_ring () {}
133 };
134
135 static void cl_integer_ring_destructor (cl_heap* pointer)
136 {
137         (*(cl_heap_integer_ring*)pointer).~cl_heap_integer_ring();
138 }
139
140 static void cl_integer_ring_dprint (cl_heap* pointer)
141 {
142         unused pointer;
143         fprint(cl_debugout, "(cl_integer_ring) cl_I_ring");
144 }
145
146 cl_class cl_class_integer_ring = {
147         cl_integer_ring_destructor,
148         cl_class_flags_number_ring,
149         cl_integer_ring_dprint
150 };
151
152 // Constructor.
153 template <>
154 inline cl_integer_ring::cl_specialized_number_ring ()
155         : cl_number_ring (new cl_heap_integer_ring()) {}
156
157 const cl_integer_ring cl_I_ring;
158
159 }  // namespace cln
160
161 CL_PROVIDE_END(cl_I_ring)