1 // Ring of real numbers.
9 #include "cln/real_ring.h"
17 #include "cln/real_io.h"
21 static void R_fprint (cl_heap_ring* R, std::ostream& stream, const _cl_ring_element& x)
24 fprint(stream,The(cl_R)(x));
27 static bool R_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
30 return equal(The(cl_R)(x),The(cl_R)(y));
33 static const _cl_ring_element R_zero (cl_heap_ring* R)
35 return _cl_ring_element(R, (cl_R)0);
38 static bool R_zerop (cl_heap_ring* R, const _cl_ring_element& x)
41 // Here we return true only if x is the *exact* zero. Because we
42 // don't want the degree of polynomials to depend on rounding errors.
43 // For all ring theoretic purposes, we treat 0.0 as if it were a
45 return exact_zerop(The(cl_R)(x));
48 static const _cl_ring_element R_plus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
50 return _cl_ring_element(R, The(cl_R)(x) + The(cl_R)(y));
53 static const _cl_ring_element R_minus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
55 return _cl_ring_element(R, The(cl_R)(x) - The(cl_R)(y));
58 static const _cl_ring_element R_uminus (cl_heap_ring* R, const _cl_ring_element& x)
60 return _cl_ring_element(R, - The(cl_R)(x));
63 static const _cl_ring_element R_one (cl_heap_ring* R)
65 return _cl_ring_element(R, (cl_R)1);
68 static const _cl_ring_element R_canonhom (cl_heap_ring* R, const cl_I& x)
70 return _cl_ring_element(R, (cl_R)x);
73 static const _cl_ring_element R_mul (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
75 return _cl_ring_element(R, The(cl_R)(x) * The(cl_R)(y));
78 static const _cl_ring_element R_square (cl_heap_ring* R, const _cl_ring_element& x)
80 return _cl_ring_element(R, square(The(cl_R)(x)));
83 static const _cl_ring_element R_expt_pos (cl_heap_ring* R, const _cl_ring_element& x, const cl_I& y)
85 return _cl_ring_element(R, expt(The(cl_R)(x),y));
88 static bool cl_R_p (const cl_number& x)
90 return (!x.pointer_p()
91 || (x.pointer_type()->flags & cl_class_flags_subclass_real) != 0);
94 static cl_ring_setops R_setops = {
98 static cl_ring_addops R_addops = {
105 static cl_ring_mulops R_mulops = {
113 static cl_number_ring_ops<cl_R> R_ops = {
125 class cl_heap_real_ring : public cl_heap_number_ring {
126 SUBCLASS_cl_heap_ring()
130 : cl_heap_number_ring (&R_setops,&R_addops,&R_mulops,
131 (cl_number_ring_ops<cl_number>*) &R_ops)
132 { type = &cl_class_real_ring; }
134 ~cl_heap_real_ring () {}
137 static void cl_real_ring_destructor (cl_heap* pointer)
139 (*(cl_heap_real_ring*)pointer).~cl_heap_real_ring();
142 static void cl_real_ring_dprint (cl_heap* pointer)
145 fprint(cl_debugout, "(cl_real_ring) cl_R_ring");
148 cl_class cl_class_real_ring = {
149 cl_real_ring_destructor,
150 cl_class_flags_number_ring,
156 inline cl_real_ring::cl_specialized_number_ring ()
157 : cl_number_ring (new cl_heap_real_ring()) {}
159 const cl_real_ring cl_R_ring;
163 CL_PROVIDE_END(cl_R_ring)