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