]> www.ginac.de Git - cln.git/blob - src/polynomial/elem/cl_UP.cc
The patch of 2005-05-01 made it impossible to test the type of a cl_UP
[cln.git] / src / polynomial / elem / cl_UP.cc
1 // Univariate Polynomial operations.
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 CL_PROVIDE(cl_UP)
7
8 // Specification.
9 #define CL_GV_NO_RANGECHECKS
10 #define CL_SV_NO_RANGECHECKS
11 #include "cln/univpoly.h"
12 #include "cl_UP.h"
13
14
15 // Implementation.
16
17 #include "cln/output.h"
18
19 namespace cln {
20
21 cl_symbol cl_univpoly_varname_key = (cl_symbol)(cl_string)"variable name";
22
23 // Prepare for looking into a polynomial.
24   #define DeclarePoly(type,x)  \
25     const type& __tmp_##x = *(const type*) &(x).rep;                    \
26     const type& x = __tmp_##x;
27   #define DeclareMutablePoly(type,x)  \
28     type& __tmp_##x = *(type*) &(x).rep;                                \
29     type& x = __tmp_##x;
30
31 }  // namespace cln
32
33 // Four different implementations of the polynomial operations, for efficiency:
34 #include "cl_UP_number.h"  // polynomials over number rings
35 #include "cl_UP_MI.h"      // polynomials over modular integer rings
36 #include "cl_UP_GF2.h"     // polynomials over the modular integer ring GF(2)
37 #include "cl_UP_gen.h"     // polynomials over all other rings
38
39 namespace cln {
40
41 static void cl_univpoly_ring_destructor (cl_heap* pointer)
42 {
43         (*(cl_heap_univpoly_ring*)pointer).~cl_heap_univpoly_ring();
44 }
45
46 cl_class cl_class_univpoly_ring = {
47         cl_univpoly_ring_destructor,
48         cl_class_flags_univpoly_ring
49 };
50
51 cl_heap_univpoly_ring::cl_heap_univpoly_ring (const cl_ring& r, cl_univpoly_setops* setopv, cl_univpoly_addops* addopv, cl_univpoly_mulops* mulopv, cl_univpoly_modulops* modulopv, cl_univpoly_polyops* polyopv)
52         : setops (setopv), addops (addopv), mulops (mulopv), modulops (modulopv), polyops (polyopv),
53           _basering (r)
54 {
55         refcount = 0; // will be incremented by the `cl_univpoly_ring' constructor
56         type = &cl_class_univpoly_ring;
57 }
58
59
60 // Create a new univariate polynomial ring.
61
62 cl_heap_univpoly_ring* cl_make_univpoly_ring (const cl_ring& r)
63 {
64         if (r.pointer_type()->flags & cl_class_flags_number_ring)
65                 return new cl_heap_num_univpoly_ring(r);
66         else if (r.pointer_type()->flags & cl_class_flags_modint_ring) {
67                 if (((cl_heap_modint_ring*)r.heappointer)->modulus == 2)
68                         return new cl_heap_gf2_univpoly_ring(r);
69                 else
70                         return new cl_heap_modint_univpoly_ring(r);
71         } else
72                 return new cl_heap_gen_univpoly_ring(r);
73 }
74
75 }  // namespace cln
76
77 CL_PROVIDE_END(cl_UP)