]> www.ginac.de Git - cln.git/blob - src/rational/ring/cl_RA_ring.cc
Don't generate cln.texi from cln.tex any more.
[cln.git] / src / rational / ring / cl_RA_ring.cc
1 // Ring of rational numbers.
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 CL_PROVIDE(cl_RA_ring)
7
8 // Specification.
9 #include "cln/rational_ring.h"
10
11
12 // Implementation.
13
14 #include "cln/rational.h"
15 #include "cln/rational_io.h"
16 #include "cl_RA.h"
17
18 namespace cln {
19
20 static void RA_fprint (cl_heap_ring* R, std::ostream& stream, const _cl_ring_element& x)
21 {
22         unused R;
23         fprint(stream,The(cl_RA)(x));
24 }
25
26 static bool RA_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
27 {
28         unused R;
29         return equal(The(cl_RA)(x),The(cl_RA)(y));
30 }
31
32 static const _cl_ring_element RA_zero (cl_heap_ring* R)
33 {
34         return _cl_ring_element(R, (cl_RA)0);
35 }
36
37 static bool RA_zerop (cl_heap_ring* R, const _cl_ring_element& x)
38 {
39         unused R;
40         return zerop(The(cl_RA)(x));
41 }
42
43 static const _cl_ring_element RA_plus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
44 {
45         return _cl_ring_element(R, The(cl_RA)(x) + The(cl_RA)(y));
46 }
47
48 static const _cl_ring_element RA_minus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
49 {
50         return _cl_ring_element(R, The(cl_RA)(x) - The(cl_RA)(y));
51 }
52
53 static const _cl_ring_element RA_uminus (cl_heap_ring* R, const _cl_ring_element& x)
54 {
55         return _cl_ring_element(R, - The(cl_RA)(x));
56 }
57
58 static const _cl_ring_element RA_one (cl_heap_ring* R)
59 {
60         return _cl_ring_element(R, (cl_RA)1);
61 }
62
63 static const _cl_ring_element RA_canonhom (cl_heap_ring* R, const cl_I& x)
64 {
65         return _cl_ring_element(R, (cl_RA)x);
66 }
67
68 static const _cl_ring_element RA_mul (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
69 {
70         return _cl_ring_element(R, The(cl_RA)(x) * The(cl_RA)(y));
71 }
72
73 static const _cl_ring_element RA_square (cl_heap_ring* R, const _cl_ring_element& x)
74 {
75         return _cl_ring_element(R, square(The(cl_RA)(x)));
76 }
77
78 static const _cl_ring_element RA_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_RA)(x),y));
81 }
82
83 static bool cl_RA_p (const cl_number& x)
84 {
85         return (!x.pointer_p()
86                 ? x.nonpointer_tag() == cl_FN_tag
87                 : (x.pointer_type()->flags & cl_class_flags_subclass_rational) != 0);
88 }
89
90 static cl_ring_setops RA_setops = {
91         RA_fprint,
92         RA_equal
93 };
94 static cl_ring_addops RA_addops = {
95         RA_zero,
96         RA_zerop,
97         RA_plus,
98         RA_minus,
99         RA_uminus
100 };
101 static cl_ring_mulops RA_mulops = {
102         RA_one,
103         RA_canonhom,
104         RA_mul,
105         RA_square,
106         RA_expt_pos
107 };
108
109 static cl_number_ring_ops<cl_RA> RA_ops = {
110         cl_RA_p,
111         equal,
112         zerop,
113         operator+,
114         operator-,
115         operator-,
116         operator*,
117         square,
118         expt_pos
119 };
120
121 class cl_heap_rational_ring : public cl_heap_number_ring {
122         SUBCLASS_cl_heap_ring()
123 public:
124         // Constructor.
125         cl_heap_rational_ring ()
126                 : cl_heap_number_ring (&RA_setops,&RA_addops,&RA_mulops,
127                                        (cl_number_ring_ops<cl_number>*) &RA_ops)
128                 { type = &cl_class_rational_ring; }
129         // Destructor.
130         ~cl_heap_rational_ring () {}
131 };
132
133 static void cl_rational_ring_destructor (cl_heap* pointer)
134 {
135         (*(cl_heap_rational_ring*)pointer).~cl_heap_rational_ring();
136 }
137
138 static void cl_rational_ring_dprint (cl_heap* pointer)
139 {
140         unused pointer;
141         fprint(cl_debugout, "(cl_rational_ring) cl_RA_ring");
142 }
143
144 cl_class cl_class_rational_ring = {
145         cl_rational_ring_destructor,
146         cl_class_flags_number_ring,
147         cl_rational_ring_dprint
148 };
149
150 // Constructor.
151 template <>
152 inline cl_rational_ring::cl_specialized_number_ring ()
153         : cl_number_ring (new cl_heap_rational_ring()) {}
154
155 const cl_rational_ring cl_RA_ring;
156
157 }  // namespace cln
158
159 CL_PROVIDE_END(cl_RA_ring)