From 21b500ee7067d2b241fc9150af52eeb34a8ca29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Pe=C3=B1aranda?= Date: Thu, 19 Oct 2006 15:58:21 +0000 Subject: [PATCH] Implemented SignAt_1 for coefficients. --- .../include/CGAL/Gbrs_functors.h | 6 +++- .../include/CGAL/Gbrs_polynomial_1.C | 36 +++++++++---------- .../include/CGAL/Gbrs_polynomial_1.h | 2 +- .../test/Gbrs_polynomial/Gbrs_polynomial_1.C | 10 ++++-- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_functors.h b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_functors.h index 62f8b530e93..687d0aee8e7 100644 --- a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_functors.h +++ b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_functors.h @@ -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 diff --git a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_polynomial_1.C b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_polynomial_1.C index cde875db807..f2a04ef65b3 100644 --- a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_polynomial_1.C +++ b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_polynomial_1.C @@ -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 { diff --git a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_polynomial_1.h b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_polynomial_1.h index a16c220b6d8..1901f55be23 100644 --- a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_polynomial_1.h +++ b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_polynomial_1.h @@ -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 &); diff --git a/Algebraic_kernel_GBRS/test/Gbrs_polynomial/Gbrs_polynomial_1.C b/Algebraic_kernel_GBRS/test/Gbrs_polynomial/Gbrs_polynomial_1.C index 32223107380..d6abf516e23 100644 --- a/Algebraic_kernel_GBRS/test/Gbrs_polynomial/Gbrs_polynomial_1.C +++ b/Algebraic_kernel_GBRS/test/Gbrs_polynomial/Gbrs_polynomial_1.C @@ -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; }