1 // Ring of complex numbers.
9 #include "cln/complex_ring.h"
14 #include "cln/complex.h"
15 #include "cln/complex_io.h"
20 static void N_fprint (cl_heap_ring* R, cl_ostream stream, const _cl_ring_element& x)
23 fprint(stream,The(cl_N)(x));
26 static cl_boolean N_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
29 return equal(The(cl_N)(x),The(cl_N)(y));
32 static const _cl_ring_element N_zero (cl_heap_ring* R)
34 return _cl_ring_element(R, (cl_N)0);
37 static cl_boolean N_zerop (cl_heap_ring* R, const _cl_ring_element& x)
40 // Here we return true only if x is the *exact* zero. Because we
41 // don't want the degree of polynomials to depend on rounding errors.
42 // For all ring theoretic purposes, we treat 0.0, 0+0.0i etc. as if
43 // they were zero divisors.
44 return exact_zerop(The(cl_N)(x));
47 static const _cl_ring_element N_plus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
49 return _cl_ring_element(R, The(cl_N)(x) + The(cl_N)(y));
52 static const _cl_ring_element N_minus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
54 return _cl_ring_element(R, The(cl_N)(x) - The(cl_N)(y));
57 static const _cl_ring_element N_uminus (cl_heap_ring* R, const _cl_ring_element& x)
59 return _cl_ring_element(R, - The(cl_N)(x));
62 static const _cl_ring_element N_one (cl_heap_ring* R)
64 return _cl_ring_element(R, (cl_N)1);
67 static const _cl_ring_element N_canonhom (cl_heap_ring* R, const cl_I& x)
69 return _cl_ring_element(R, (cl_N)x);
72 static const _cl_ring_element N_mul (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
74 return _cl_ring_element(R, The(cl_N)(x) * The(cl_N)(y));
77 static const _cl_ring_element N_square (cl_heap_ring* R, const _cl_ring_element& x)
79 return _cl_ring_element(R, square(The(cl_N)(x)));
82 static const _cl_ring_element N_expt_pos (cl_heap_ring* R, const _cl_ring_element& x, const cl_I& y)
84 return _cl_ring_element(R, expt(The(cl_N)(x),y));
87 static cl_boolean cl_N_p (const cl_number& x)
91 || (x.pointer_type()->flags & cl_class_flags_subclass_complex) != 0
95 static cl_ring_setops N_setops = {
99 static cl_ring_addops N_addops = {
106 static cl_ring_mulops N_mulops = {
114 static cl_number_ring_ops<cl_N> N_ops = {
126 class cl_heap_complex_ring : public cl_heap_number_ring {
127 SUBCLASS_cl_heap_ring()
130 cl_heap_complex_ring ()
131 : cl_heap_number_ring (&N_setops,&N_addops,&N_mulops,
132 (cl_number_ring_ops<cl_number>*) &N_ops)
133 { type = &cl_class_complex_ring; }
135 ~cl_heap_complex_ring () {}
138 static void cl_complex_ring_destructor (cl_heap* pointer)
140 (*(cl_heap_complex_ring*)pointer).~cl_heap_complex_ring();
143 static void cl_complex_ring_dprint (cl_heap* pointer)
146 fprint(cl_debugout, "(cl_complex_ring) cl_C_ring");
149 cl_class cl_class_complex_ring = {
150 cl_complex_ring_destructor,
151 cl_class_flags_number_ring,
152 cl_complex_ring_dprint
156 inline cl_complex_ring::cl_specialized_number_ring ()
157 : cl_number_ring (new cl_heap_complex_ring()) {}
159 const cl_complex_ring cl_C_ring;
163 CL_PROVIDE_END(cl_C_ring)