1 // Ring of complex numbers.
9 #include "cl_complex_ring.h"
14 #include "cl_complex.h"
15 #include "cl_complex_io.h"
18 static void N_fprint (cl_heap_ring* R, cl_ostream stream, const _cl_ring_element& x)
21 fprint(stream,The(cl_N)(x));
24 static cl_boolean N_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
27 return cl_equal(The(cl_N)(x),The(cl_N)(y));
30 static const _cl_ring_element N_zero (cl_heap_ring* R)
32 return _cl_ring_element(R, (cl_N)0);
35 static cl_boolean N_zerop (cl_heap_ring* R, const _cl_ring_element& x)
38 // Here we return true only if x is the *exact* zero. Because we
39 // don't want the degree of polynomials to depend on rounding errors.
40 // For all ring theoretic purposes, we treat 0.0, 0+0.0i etc. as if
41 // they were zero divisors.
42 return exact_zerop(The(cl_N)(x));
45 static const _cl_ring_element N_plus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
47 return _cl_ring_element(R, The(cl_N)(x) + The(cl_N)(y));
50 static const _cl_ring_element N_minus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
52 return _cl_ring_element(R, The(cl_N)(x) - The(cl_N)(y));
55 static const _cl_ring_element N_uminus (cl_heap_ring* R, const _cl_ring_element& x)
57 return _cl_ring_element(R, - The(cl_N)(x));
60 static const _cl_ring_element N_one (cl_heap_ring* R)
62 return _cl_ring_element(R, (cl_N)1);
65 static const _cl_ring_element N_canonhom (cl_heap_ring* R, const cl_I& x)
67 return _cl_ring_element(R, (cl_N)x);
70 static const _cl_ring_element N_mul (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
72 return _cl_ring_element(R, The(cl_N)(x) * The(cl_N)(y));
75 static const _cl_ring_element N_square (cl_heap_ring* R, const _cl_ring_element& x)
77 return _cl_ring_element(R, square(The(cl_N)(x)));
80 static const _cl_ring_element N_expt_pos (cl_heap_ring* R, const _cl_ring_element& x, const cl_I& y)
82 return _cl_ring_element(R, expt(The(cl_N)(x),y));
85 static cl_boolean cl_N_p (const cl_number& x)
89 || (x.pointer_type()->flags & cl_class_flags_subclass_complex) != 0
93 static cl_ring_setops N_setops = {
97 static cl_ring_addops N_addops = {
104 static cl_ring_mulops N_mulops = {
112 static cl_number_ring_ops<cl_N> N_ops = {
124 class cl_heap_complex_ring : public cl_heap_number_ring {
125 SUBCLASS_cl_heap_ring()
128 cl_heap_complex_ring ()
129 : cl_heap_number_ring (&N_setops,&N_addops,&N_mulops,
130 (cl_number_ring_ops<cl_number>*) &N_ops)
131 { type = &cl_class_complex_ring; }
133 ~cl_heap_complex_ring () {}
136 static void cl_complex_ring_destructor (cl_heap* pointer)
138 (*(cl_heap_complex_ring*)pointer).~cl_heap_complex_ring();
141 static void cl_complex_ring_dprint (cl_heap* pointer)
144 fprint(cl_debugout, "(cl_complex_ring) cl_C_ring");
147 cl_class cl_class_complex_ring = {
148 cl_complex_ring_destructor,
149 cl_class_flags_number_ring,
150 cl_complex_ring_dprint
154 inline cl_complex_ring::cl_specialized_number_ring ()
155 : cl_number_ring (new cl_heap_complex_ring()) {}
157 const cl_complex_ring cl_C_ring;
159 CL_PROVIDE_END(cl_C_ring)