]> www.ginac.de Git - cln.git/blob - src/complex/ring/cl_C_ring.cc
- Compatibility was not really broken, so: C=0, R=1, A=0.
[cln.git] / src / complex / ring / cl_C_ring.cc
1 // Ring of complex numbers.
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 CL_PROVIDE(cl_C_ring)
7
8 // Specification.
9 #include "cl_complex_ring.h"
10
11
12 // Implementation.
13
14 #include "cl_complex.h"
15 #include "cl_complex_io.h"
16 #include "cl_C.h"
17
18 static void N_fprint (cl_heap_ring* R, cl_ostream stream, const _cl_ring_element& x)
19 {
20         unused R;
21         fprint(stream,The(cl_N)(x));
22 }
23
24 static cl_boolean N_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
25 {
26         unused R;
27         return cl_equal(The(cl_N)(x),The(cl_N)(y));
28 }
29
30 static const _cl_ring_element N_zero (cl_heap_ring* R)
31 {
32         return _cl_ring_element(R, (cl_N)0);
33 }
34
35 static cl_boolean N_zerop (cl_heap_ring* R, const _cl_ring_element& x)
36 {
37         unused R;
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));
43 }
44
45 static const _cl_ring_element N_plus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
46 {
47         return _cl_ring_element(R, The(cl_N)(x) + The(cl_N)(y));
48 }
49
50 static const _cl_ring_element N_minus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
51 {
52         return _cl_ring_element(R, The(cl_N)(x) - The(cl_N)(y));
53 }
54
55 static const _cl_ring_element N_uminus (cl_heap_ring* R, const _cl_ring_element& x)
56 {
57         return _cl_ring_element(R, - The(cl_N)(x));
58 }
59
60 static const _cl_ring_element N_one (cl_heap_ring* R)
61 {
62         return _cl_ring_element(R, (cl_N)1);
63 }
64
65 static const _cl_ring_element N_canonhom (cl_heap_ring* R, const cl_I& x)
66 {
67         return _cl_ring_element(R, (cl_N)x);
68 }
69
70 static const _cl_ring_element N_mul (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
71 {
72         return _cl_ring_element(R, The(cl_N)(x) * The(cl_N)(y));
73 }
74
75 static const _cl_ring_element N_square (cl_heap_ring* R, const _cl_ring_element& x)
76 {
77         return _cl_ring_element(R, square(The(cl_N)(x)));
78 }
79
80 static const _cl_ring_element N_expt_pos (cl_heap_ring* R, const _cl_ring_element& x, const cl_I& y)
81 {
82         return _cl_ring_element(R, expt(The(cl_N)(x),y));
83 }
84
85 static cl_boolean cl_N_p (const cl_number& x)
86 {
87         return (cl_boolean)
88                (!x.pointer_p()
89                 || (x.pointer_type()->flags & cl_class_flags_subclass_complex) != 0
90                );
91 }
92
93 static cl_ring_setops N_setops = {
94         N_fprint,
95         N_equal
96 };
97 static cl_ring_addops N_addops = {
98         N_zero,
99         N_zerop,
100         N_plus,
101         N_minus,
102         N_uminus
103 };
104 static cl_ring_mulops N_mulops = {
105         N_one,
106         N_canonhom,
107         N_mul,
108         N_square,
109         N_expt_pos
110 };
111
112 static cl_number_ring_ops<cl_N> N_ops = {
113         cl_N_p,
114         cl_equal,
115         exact_zerop,
116         operator+,
117         operator-,
118         operator-,
119         operator*,
120         square,
121         expt
122 };
123
124 class cl_heap_complex_ring : public cl_heap_number_ring {
125         SUBCLASS_cl_heap_ring()
126 public:
127         // Constructor.
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; }
132         // Destructor.
133         ~cl_heap_complex_ring () {}
134 };
135
136 static void cl_complex_ring_destructor (cl_heap* pointer)
137 {
138         (*(cl_heap_complex_ring*)pointer).~cl_heap_complex_ring();
139 }
140
141 static void cl_complex_ring_dprint (cl_heap* pointer)
142 {
143         unused pointer;
144         fprint(cl_debugout, "(cl_complex_ring) cl_C_ring");
145 }
146
147 cl_class cl_class_complex_ring = {
148         cl_complex_ring_destructor,
149         cl_class_flags_number_ring,
150         cl_complex_ring_dprint
151 };
152
153 // Constructor.
154 inline cl_complex_ring::cl_specialized_number_ring ()
155         : cl_number_ring (new cl_heap_complex_ring()) {}
156
157 const cl_complex_ring cl_C_ring;
158
159 CL_PROVIDE_END(cl_C_ring)