9 #include "cln/integer_ring.h"
14 #include "cln/integer.h"
15 #include "cln/integer_io.h"
16 #define zerop zerop_inline
22 static void I_fprint (cl_heap_ring* R, std::ostream& stream, const _cl_ring_element& x)
25 fprint(stream,The(cl_I)(x));
28 static bool I_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
31 return equal(The(cl_I)(x),The(cl_I)(y));
34 static const _cl_ring_element I_zero (cl_heap_ring* R)
36 return _cl_ring_element(R, (cl_I)0);
39 static bool CL_FLATTEN I_zerop (cl_heap_ring* R, const _cl_ring_element& x)
42 return zerop_inline(The(cl_I)(x));
45 static const _cl_ring_element I_plus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
47 return _cl_ring_element(R, The(cl_I)(x) + The(cl_I)(y));
50 static const _cl_ring_element I_minus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
52 return _cl_ring_element(R, The(cl_I)(x) - The(cl_I)(y));
55 static const _cl_ring_element I_uminus (cl_heap_ring* R, const _cl_ring_element& x)
57 return _cl_ring_element(R, - The(cl_I)(x));
60 static const _cl_ring_element I_one (cl_heap_ring* R)
62 return _cl_ring_element(R, (cl_I)1);
65 static const _cl_ring_element I_canonhom (cl_heap_ring* R, const cl_I& x)
67 return _cl_ring_element(R, (cl_I)x);
70 static const _cl_ring_element I_mul (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
72 return _cl_ring_element(R, The(cl_I)(x) * The(cl_I)(y));
75 static const _cl_ring_element I_square (cl_heap_ring* R, const _cl_ring_element& x)
77 return _cl_ring_element(R, square(The(cl_I)(x)));
80 static const _cl_ring_element I_expt_pos (cl_heap_ring* R, const _cl_ring_element& x, const cl_I& y)
82 return _cl_ring_element(R, expt_pos(The(cl_I)(x),y));
85 static bool cl_I_p (const cl_number& x)
87 return (!x.pointer_p()
88 ? x.nonpointer_tag() == cl_FN_tag
89 : x.pointer_type() == &cl_class_bignum);
92 static cl_ring_setops I_setops = {
96 static cl_ring_addops I_addops = {
103 static cl_ring_mulops I_mulops = {
111 static cl_number_ring_ops<cl_I> I_ops = {
123 class cl_heap_integer_ring : public cl_heap_number_ring {
124 SUBCLASS_cl_heap_ring()
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; }
132 ~cl_heap_integer_ring () {}
135 static void cl_integer_ring_destructor (cl_heap* pointer)
137 (*(cl_heap_integer_ring*)pointer).~cl_heap_integer_ring();
140 static void cl_integer_ring_dprint (cl_heap* pointer)
143 fprint(cl_debugout, "(cl_integer_ring) cl_I_ring");
146 cl_class cl_class_integer_ring = {
147 cl_integer_ring_destructor,
148 cl_class_flags_number_ring,
149 cl_integer_ring_dprint
154 inline cl_integer_ring::cl_specialized_number_ring ()
155 : cl_number_ring (new cl_heap_integer_ring()) {}
157 const cl_integer_ring cl_I_ring;
161 CL_PROVIDE_END(cl_I_ring)