1 // Ring of real numbers.
4 #include "base/cl_sysdep.h"
7 #include "cln/real_ring.h"
13 #include "real/cl_R.h"
15 #include "cln/real_io.h"
19 static void R_fprint (cl_heap_ring* R, std::ostream& stream, const _cl_ring_element& x)
22 fprint(stream,The(cl_R)(x));
25 static bool R_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
28 return equal(The(cl_R)(x),The(cl_R)(y));
31 static const _cl_ring_element R_zero (cl_heap_ring* R)
33 return _cl_ring_element(R, (cl_R)0);
36 static bool R_zerop (cl_heap_ring* R, const _cl_ring_element& x)
39 // Here we return true only if x is the *exact* zero. Because we
40 // don't want the degree of polynomials to depend on rounding errors.
41 // For all ring theoretic purposes, we treat 0.0 as if it were a
43 return exact_zerop(The(cl_R)(x));
46 static const _cl_ring_element R_plus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
48 return _cl_ring_element(R, The(cl_R)(x) + The(cl_R)(y));
51 static const _cl_ring_element R_minus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
53 return _cl_ring_element(R, The(cl_R)(x) - The(cl_R)(y));
56 static const _cl_ring_element R_uminus (cl_heap_ring* R, const _cl_ring_element& x)
58 return _cl_ring_element(R, - The(cl_R)(x));
61 static const _cl_ring_element R_one (cl_heap_ring* R)
63 return _cl_ring_element(R, (cl_R)1);
66 static const _cl_ring_element R_canonhom (cl_heap_ring* R, const cl_I& x)
68 return _cl_ring_element(R, (cl_R)x);
71 static const _cl_ring_element R_mul (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
73 return _cl_ring_element(R, The(cl_R)(x) * The(cl_R)(y));
76 static const _cl_ring_element R_square (cl_heap_ring* R, const _cl_ring_element& x)
78 return _cl_ring_element(R, square(The(cl_R)(x)));
81 static const _cl_ring_element R_expt_pos (cl_heap_ring* R, const _cl_ring_element& x, const cl_I& y)
83 return _cl_ring_element(R, expt(The(cl_R)(x),y));
86 static bool cl_R_p (const cl_number& x)
88 return (!x.pointer_p()
89 || (x.pointer_type()->flags & cl_class_flags_subclass_real) != 0);
92 static cl_ring_setops R_setops = {
96 static cl_ring_addops R_addops = {
103 static cl_ring_mulops R_mulops = {
111 static cl_number_ring_ops<cl_R> R_ops = {
123 class cl_heap_real_ring : public cl_heap_number_ring {
124 SUBCLASS_cl_heap_ring()
128 : cl_heap_number_ring (&R_setops,&R_addops,&R_mulops,
129 (cl_number_ring_ops<cl_number>*) &R_ops)
130 { type = &cl_class_real_ring; }
132 ~cl_heap_real_ring () {}
135 static void cl_real_ring_destructor (cl_heap* pointer)
137 (*(cl_heap_real_ring*)pointer).~cl_heap_real_ring();
140 static void cl_real_ring_dprint (cl_heap* pointer)
143 fprint(cl_debugout, "(cl_real_ring) cl_R_ring");
146 static cl_heap_real_ring* cl_heap_real_ring_instance;
147 cl_class cl_class_real_ring;
151 inline cl_real_ring::cl_specialized_number_ring ()
152 : cl_number_ring (cl_heap_real_ring_instance) {}
154 const cl_real_ring cl_R_ring = cl_R_ring;
156 int cl_R_ring_init_helper::count = 0;
158 cl_R_ring_init_helper::cl_R_ring_init_helper()
161 cl_class_real_ring.destruct = cl_real_ring_destructor;
162 cl_class_real_ring.flags = cl_class_flags_number_ring;
163 cl_class_real_ring.dprint = cl_real_ring_dprint;
164 cl_heap_real_ring_instance = new cl_heap_real_ring();
165 new((void *)&cl_R_ring) cl_real_ring();
169 cl_R_ring_init_helper::~cl_R_ring_init_helper()
172 delete cl_heap_real_ring_instance;