]> www.ginac.de Git - cln.git/blob - src/integer/ring/cl_I_ring.cc
5629e1f6420c45ad8e784a3c386e3b5f24e89484
[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 #include "cl_I.h"
17
18 namespace cln {
19
20 static void I_fprint (cl_heap_ring* R, std::ostream& stream, const _cl_ring_element& x)
21 {
22         unused R;
23         fprint(stream,The(cl_I)(x));
24 }
25
26 static cl_boolean I_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
27 {
28         unused R;
29         return equal(The(cl_I)(x),The(cl_I)(y));
30 }
31
32 static const _cl_ring_element I_zero (cl_heap_ring* R)
33 {
34         return _cl_ring_element(R, (cl_I)0);
35 }
36
37 static cl_boolean I_zerop (cl_heap_ring* R, const _cl_ring_element& x)
38 {
39         unused R;
40         return zerop(The(cl_I)(x));
41 }
42
43 static const _cl_ring_element I_plus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
44 {
45         return _cl_ring_element(R, The(cl_I)(x) + The(cl_I)(y));
46 }
47
48 static const _cl_ring_element I_minus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
49 {
50         return _cl_ring_element(R, The(cl_I)(x) - The(cl_I)(y));
51 }
52
53 static const _cl_ring_element I_uminus (cl_heap_ring* R, const _cl_ring_element& x)
54 {
55         return _cl_ring_element(R, - The(cl_I)(x));
56 }
57
58 static const _cl_ring_element I_one (cl_heap_ring* R)
59 {
60         return _cl_ring_element(R, (cl_I)1);
61 }
62
63 static const _cl_ring_element I_canonhom (cl_heap_ring* R, const cl_I& x)
64 {
65         return _cl_ring_element(R, (cl_I)x);
66 }
67
68 static const _cl_ring_element I_mul (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
69 {
70         return _cl_ring_element(R, The(cl_I)(x) * The(cl_I)(y));
71 }
72
73 static const _cl_ring_element I_square (cl_heap_ring* R, const _cl_ring_element& x)
74 {
75         return _cl_ring_element(R, square(The(cl_I)(x)));
76 }
77
78 static const _cl_ring_element I_expt_pos (cl_heap_ring* R, const _cl_ring_element& x, const cl_I& y)
79 {
80         return _cl_ring_element(R, expt_pos(The(cl_I)(x),y));
81 }
82
83 static cl_boolean cl_I_p (const cl_number& x)
84 {
85         return (cl_boolean)
86                (!x.pointer_p()
87                 ? x.nonpointer_tag() == cl_FN_tag
88                 : x.pointer_type() == &cl_class_bignum
89                );
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 inline cl_integer_ring::cl_specialized_number_ring ()
154         : cl_number_ring (new cl_heap_integer_ring()) {}
155
156 const cl_integer_ring cl_I_ring;
157
158 }  // namespace cln
159
160 CL_PROVIDE_END(cl_I_ring)