]> www.ginac.de Git - cln.git/blob - src/modinteger/cl_MI_fix16.h
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / modinteger / cl_MI_fix16.h
1 // 1 < m < 2^16, standard representation
2
3 namespace cln {
4
5 static const _cl_MI fix16_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
6 {
7         var uint32 zr = FN_to_UL(x.rep) + FN_to_UL(y.rep);
8         if (zr >= FN_to_UL(R->modulus)) { zr = zr - FN_to_UL(R->modulus); }
9         return _cl_MI(R, L_to_FN(zr));
10 }
11
12 static const _cl_MI fix16_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
13 {
14         var uint32 xr = FN_to_UL(x.rep);
15         var uint32 yr = FN_to_UL(y.rep);
16         var sint32 zr = xr - yr;
17         if (zr < 0) { zr = zr + FN_to_UL(R->modulus); }
18         return _cl_MI(R, L_to_FN(zr));
19 }
20
21 static const _cl_MI fix16_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
22 {
23         var uint32 xr = FN_to_UL(x.rep);
24         var uint32 zr = (xr==0 ? 0 : FN_to_UL(R->modulus)-xr);
25         return _cl_MI(R, L_to_FN(zr));
26 }
27
28 static const _cl_MI fix16_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
29 {
30         var uint32 xr = FN_to_UL(x.rep);
31         var uint32 yr = FN_to_UL(y.rep);
32         var uint32 zr = mulu16(xr,yr);
33         divu_3216_1616(zr,FN_to_UL(R->modulus),,zr=);
34         return _cl_MI(R, L_to_FN(zr));
35 }
36
37 static const _cl_MI fix16_square (cl_heap_modint_ring* R, const _cl_MI& x)
38 {
39         var uint32 xr = FN_to_UL(x.rep);
40         var uint32 zr = mulu16(xr,xr);
41         divu_3216_1616(zr,FN_to_UL(R->modulus),,zr=);
42         return _cl_MI(R, L_to_FN(zr));
43 }
44
45 static cl_modint_addops fix16_addops = {
46         std_zero,
47         std_zerop,
48         fix16_plus,
49         fix16_minus,
50         fix16_uminus
51 };
52 static cl_modint_mulops fix16_mulops = {
53         std_one,
54         std_canonhom,
55         fix16_mul,
56         fix16_square,
57         std_expt_pos,
58         std_recip,
59         std_div,
60         std_expt,
61         std_reduce_modulo,
62         std_retract
63 };
64
65 class cl_heap_modint_ring_fix16 : public cl_heap_modint_ring {
66         SUBCLASS_cl_heap_modint_ring()
67 public:
68         // Constructor.
69         cl_heap_modint_ring_fix16 (const cl_I& m)
70                 : cl_heap_modint_ring (m, &std_setops, &fix16_addops, &fix16_mulops) {}
71         // Virtual destructor.
72         ~cl_heap_modint_ring_fix16 () {}
73 };
74
75 }  // namespace cln