1 #include <polylib/polylibgmp.h>
5 * Vector p3 is a linear combination of two vectors (p1 and p2) such that
6 * p3[pos] is zero. First element of each vector (p1,p2,p3) is a status
7 * element and is not changed in p3. The value of 'pos' may be 0 however.
8 * The parameter 'length' does not include status element one.
10 * This function was copied from the PolyLib source.
12 void Combine(Value
*p1
, Value
*p2
, Value
*p3
, int pos
, unsigned length
) {
15 Value abs_a1
,abs_a2
,neg_a1
;
17 /* Initialize all the 'Value' variables */
18 value_init(a1
); value_init(a2
); value_init(gcd
);
19 value_init(abs_a1
); value_init(abs_a2
); value_init(neg_a1
);
22 value_assign(a1
,p1
[pos
]);
25 value_assign(a2
,p2
[pos
]);
28 value_absolute(abs_a1
,a1
);
31 value_absolute(abs_a2
,a2
);
33 /* gcd = Gcd(abs(a1), abs(a2)) */
34 Gcd(abs_a1
,abs_a2
,&gcd
);
37 value_division (a1
,a1
,gcd
);
40 value_division (a2
,a2
,gcd
);
43 value_oppose(neg_a1
,a1
);
45 Vector_Combine(p1
+1,p2
+1,p3
+1,a2
,neg_a1
,length
);
46 Vector_Normalize(p3
+1,length
);
48 /* Clear all the 'Value' variables */
49 value_clear(a1
); value_clear(a2
); value_clear(gcd
);
50 value_clear(abs_a1
); value_clear(abs_a2
); value_clear(neg_a1
);