Implemented SignAt_1 for coefficients.

This commit is contained in:
Luis Peñaranda 2006-10-19 15:58:21 +00:00
parent 2b32238e75
commit 21b500ee70
4 changed files with 32 additions and 22 deletions

View File

@ -136,7 +136,11 @@ class SignAt_1 {
result_type operator() (const Polynomial_1 &p,
const Coefficient_1 &r) const {
CGAL_assertion_msg (false, "not implemented yet");
Coefficient_1 c = p.eval (r);
if (c < 0)
return NEGATIVE;
if (c > 0)
return POSITIVE;
return ZERO;
};
}; // SignAt_1

View File

@ -167,27 +167,27 @@ void Rational_polynomial_1::get_coef (int pow_x, mpz_t *c) const {
return result;
};*/
/*CGAL::Gmpq Rational_polynomial_1::eval (const CGAL::Gmpq &x) const {
mpq_t result, x_pow, temp1, temp2;
mpq_init (result); // it's 0 now
mpq_init (x_pow);
mpq_set_si (x_pow, 1, 1); // x^0 = 1
mpq_init (temp1);
mpq_init (temp2);
CGAL::Gmpz Rational_polynomial_1::eval (const CGAL::Gmpz &x) const {
mpz_t result, x_pow, temp1, temp2;
mpz_init (result); // it's 0 now
mpz_init (x_pow);
mpz_set_si (x_pow, 1); // x^0 = 1
mpz_init (temp1);
mpz_init (temp2);
for (int i=0; i<=degree; ++i) { // invariant: x_pow = x^i
mpq_mul (temp1, coef[calc_index (i)], x_pow);
mpq_set (temp2, result);
mpq_add (result, temp1, temp2);
mpq_mul (temp1, x_pow, x.mpq());
mpq_set (x_pow, temp1); // to use it in the next iteration
mpz_mul (temp1, coef[calc_index (i)], x_pow);
mpz_set (temp2, result);
mpz_add (result, temp1, temp2);
mpz_mul (temp1, x_pow, x.mpz());
mpz_set (x_pow, temp1); // to use it in the next iteration
}
mpq_clear (x_pow);
mpq_clear (temp1);
mpq_clear (temp2);
CGAL::Gmpq ret(result);
mpq_clear (result);
mpz_clear (x_pow);
mpz_clear (temp1);
mpz_clear (temp2);
CGAL::Gmpz ret(result);
mpz_clear (result);
return ret;
};*/
};
// derive polynomial
Rational_polynomial_1 Rational_polynomial_1::derive () const {

View File

@ -59,7 +59,7 @@ class Rational_polynomial_1 {
inline mpz_t* get_coefs () const;
void get_coef (int, mpz_t *) const;
//CGAL::Algebraic_1 eval (const CGAL::Algebraic_1 &) const;
//CGAL::Gmpq eval (const CGAL::Gmpq &) const;
CGAL::Gmpz eval (const CGAL::Gmpz &) const;
Rational_polynomial_1 derive () const;
// assignment
Rational_polynomial_1& operator= (const Rational_polynomial_1 &);

View File

@ -81,9 +81,15 @@ int main () {
print_sign (std::cout, ker.construct_signat_1_object()(p, rootsq[0]));
std::cout << std::endl;
std::cout << "\nsign of q evaluated at the root 2 of p: ";
std::cout << "sign of q evaluated at the root 2 of p: ";
print_sign (std::cout, ker.construct_signat_1_object()(q, rootsp[2]));
std::cout << "\n" << std::endl;
std::cout << std::endl;
std::cout << "\np(3) = " << p.eval(3) << std::endl;
std::cout << "sign of p evaluated at (coefficient)3: ";
print_sign (std::cout,
ker.construct_signat_1_object()(p, Coefficient(3)));
std::cout << std::endl;
return 0;
}