source: git/libpolys/polys/templates/p_Add_q__T.cc @ cf3743

fieker-DuValspielwiese
Last change on this file since cf3743 was 38500a, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
- further template fix: added "__T" suffix to _all_ labels (incl. func. names!) - todo: finish p_Numbers.h
  • Property mode set to 100644
File size: 2.1 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/***************************************************************
5 *  File:    p_Add_q__Template.cc
6 *  Purpose: template for p_Add_q
7 *  Author:  obachman (Olaf Bachmann)
8 *  Created: 8/00
9 *  Version: $Id$
10 *******************************************************************/
11
12/***************************************************************
13 *
14 * Returns:  p + q,
15 *           Shorter, where Shorter == Length(p) + Length(q) - Length(p+q);
16 * Destroys: p, q
17 *
18 ***************************************************************/
19LINKAGE poly p_Add_q__T(poly p, poly q, int &Shorter, const ring r)
20{
21  p_Test(p, r);
22  p_Test(q, r);
23#if PDEBUG > 0
24  int l = pLength(p) + pLength(q);
25#endif
26
27  // test for trivial cases
28  Shorter = 0;
29  if (q == NULL) return p;
30  if (p == NULL) return q;
31
32  number t, n1, n2;
33  int shorter = 0;
34  spolyrec rp;
35  poly a = &rp;
36  DECLARE_LENGTH(const unsigned long length = r->CmpL_Size);
37  DECLARE_ORDSGN(const long* ordsgn = r->ordsgn);
38
39  Top:     // compare p and q w.r.t. monomial ordering
40  p_MemCmp__T(p->exp, q->exp, length, ordsgn, goto Equal, goto Greater , goto Smaller);
41
42  Equal:
43  n1 = pGetCoeff(p);
44  n2 = pGetCoeff(q);
45  #if 0
46  t = n_Add__T(n1,n2, r);
47  n_Delete__T(&n1, r);
48  #else
49  n_InpAdd__T(n1,n2,r);
50  t = n1;
51  #endif
52  n_Delete__T(&n2, r);
53  q = p_LmFreeAndNext(q, r);
54
55  if (n_IsZero__T(t, r))
56  {
57    shorter += 2;
58    n_Delete__T(&t, r);
59    p = p_LmFreeAndNext(p, r);
60  }
61  else
62  {
63    shorter++;
64    pSetCoeff0(p,t);
65    a = pNext(a) = p;
66    pIter(p);
67  }
68  if (p==NULL) { pNext(a) = q; goto Finish;}
69  if (q==NULL) { pNext(a) = p; goto Finish;}
70  goto Top;
71
72  Greater:
73  a = pNext(a) = p;
74  pIter(p);
75  if (p==NULL) { pNext(a) = q; goto Finish;}
76  goto Top;
77
78  Smaller:
79  a = pNext(a) = q;
80  pIter(q);
81  if (q==NULL) { pNext(a) = p; goto Finish;}
82  goto Top;
83
84
85  Finish:
86  Shorter = shorter;
87
88  p_Test(pNext(&rp), r);
89#if PDEBUG > 0
90  pAssume1(l - pLength(pNext(&rp)) == Shorter);
91#endif
92  return pNext(&rp);
93}
94
Note: See TracBrowser for help on using the repository browser.