mirror of https://github.com/CGAL/cgal
Algebraics are now just a collection of pointers.
This commit is contained in:
parent
850b63a4eb
commit
ddf2c32c2c
|
|
@ -128,10 +128,13 @@ Algebraic_1::Algebraic_1 (const CGAL::Gmpq &l, const CGAL::Gmpq &r) {
|
|||
mpfi_interv_q (mpfi (), l.mpq(), r.mpq());
|
||||
};
|
||||
|
||||
Algebraic_1::Algebraic_1 (const mpfi_t &i) {
|
||||
mpfi_set (mpfi (), i);
|
||||
// here, the constructor copies the address of the mpfi, not the contents
|
||||
Algebraic_1::Algebraic_1 (mpfi_t &i) {
|
||||
mpfi_clear(mpfi());
|
||||
*mpfi()=*i;
|
||||
};
|
||||
|
||||
// this is a copy constructor that copies everything, including the mpfi
|
||||
Algebraic_1::Algebraic_1 (const Algebraic_1 &i) {
|
||||
mpfi_set (mpfi (), i.mpfi ());
|
||||
set_pol (i.pol ());
|
||||
|
|
@ -141,9 +144,10 @@ Algebraic_1::Algebraic_1 (const Algebraic_1 &i) {
|
|||
};
|
||||
|
||||
// interesting constructor
|
||||
Algebraic_1::Algebraic_1 (const mpfi_t &i, const Rational_polynomial_1 &p,
|
||||
Algebraic_1::Algebraic_1 (const mpfi_ptr &i, const Rational_polynomial_1 &p,
|
||||
const int n, const int m, const int rsp) {
|
||||
mpfi_set (mpfi (), i);
|
||||
mpfi_clear(mpfi());
|
||||
*mpfi()=*i;
|
||||
set_pol (p);
|
||||
set_nr (n);
|
||||
set_mult (m);
|
||||
|
|
@ -551,7 +555,6 @@ Algebraic_1 Algebraic_1::operator- () const {
|
|||
mpfi_init (n);
|
||||
mpfi_neg (n, mpfi ());
|
||||
Algebraic_1 ret (n);
|
||||
mpfi_clear (n);
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
@ -560,7 +563,6 @@ Algebraic_1 Algebraic_1::operator+ (const Algebraic_1 &n2) const {
|
|||
mpfi_init (n);
|
||||
mpfi_add (n, mpfi (), n2.mpfi());
|
||||
Algebraic_1 ret (n);
|
||||
mpfi_clear (n);
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
@ -573,7 +575,6 @@ Algebraic_1 Algebraic_1::operator* (const Algebraic_1 &n2) const {
|
|||
mpfi_init (n);
|
||||
mpfi_mul (n, mpfi (), n2.mpfi());
|
||||
Algebraic_1 ret (n);
|
||||
mpfi_clear (n);
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
@ -698,7 +699,6 @@ Algebraic_1 Algebraic_1::operator/ (const Algebraic_1 &n2) const {
|
|||
mpfi_init (n);
|
||||
mpfi_div (n, mpfi (), n2.mpfi());
|
||||
Algebraic_1 ret (n);
|
||||
mpfi_clear (n);
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
@ -719,7 +719,6 @@ Algebraic_1 Algebraic_1::sqrt () const {
|
|||
mpfi_init (s);
|
||||
mpfi_sqrt (s, mpfi ());
|
||||
Algebraic_1 ret (s);
|
||||
mpfi_clear (s);
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public:
|
|||
int rsprec;
|
||||
|
||||
Algebraic_1_rep():poly(NULL),nr(-1),mult(-1),rsprec(0){mpfi_init(mpfI);}
|
||||
~Algebraic_1_rep () { mpfi_clear (mpfI); }
|
||||
~Algebraic_1_rep () {}
|
||||
|
||||
private:
|
||||
// Make sure it does not get accidentally copied.
|
||||
|
|
@ -107,11 +107,11 @@ public:
|
|||
Algebraic_1 (const mpq_t &, const mpq_t &);
|
||||
Algebraic_1 (const CGAL::Gmpq &, const CGAL::Gmpq &);
|
||||
Algebraic_1 (const CGAL::Gmpz &, const CGAL::Gmpz &);
|
||||
Algebraic_1 (const mpfi_t &);
|
||||
Algebraic_1 (mpfi_t &);
|
||||
Algebraic_1 (const Algebraic_1 &);
|
||||
|
||||
// the only interesting constructor
|
||||
Algebraic_1 (const mpfi_t &, const Rational_polynomial_1 &,
|
||||
Algebraic_1 (const mpfi_ptr &, const Rational_polynomial_1 &,
|
||||
const int, const int, const int);
|
||||
|
||||
Algebraic_1& operator= (const long int);
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class Solve_1 {
|
|||
bool known_to_be_square_free) const {
|
||||
if (known_to_be_square_free)
|
||||
return res;
|
||||
mpfi_t *x;
|
||||
mpfi_ptr *x;
|
||||
int nr;
|
||||
CGAL_assertion_msg (((nr = solve_1 (x, p)) >= 0),
|
||||
"error in resolution");
|
||||
|
|
@ -92,8 +92,6 @@ class Solve_1 {
|
|||
for (int i=0; i<nr; ++i) {
|
||||
// multiplicity is -1 (we didn't calculate it)
|
||||
Algebraic a (x[i], p, i, -1, CGAL_RS_DEF_PREC);
|
||||
// x[i] was mpfi_inited by RS? If so,
|
||||
mpfi_clear (x[i]);
|
||||
*(res++) = a;
|
||||
}
|
||||
free (x);
|
||||
|
|
@ -107,18 +105,6 @@ class Solve_1 {
|
|||
OutputIteratorRoots roots,
|
||||
OutputIteratorMult mult) const {
|
||||
CGAL_assertion_msg (false, "not implemented yet");
|
||||
mpfi_t *x;
|
||||
int nr;
|
||||
CGAL_assertion_msg (!((nr = solve_1 (x, p)) < 0),
|
||||
"error in resolution");
|
||||
if (nr)
|
||||
for (int i=0; i<nr; ++i) {
|
||||
Algebraic a (x[i], p);
|
||||
// x[i] was mpfi_inited by RS? If so,
|
||||
mpfi_clear (x[i]);
|
||||
*(roots++) = a;
|
||||
*(mult++) = 1; // FIXME
|
||||
}
|
||||
return std::make_pair (roots, mult);
|
||||
};
|
||||
}; // Solve_1
|
||||
|
|
|
|||
|
|
@ -34,27 +34,19 @@ int init_rs () {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int affiche_vect_ibfr (mpfi_t *&x, int index, const int ident_vect) {
|
||||
int ident_elt;
|
||||
int nb = rs_export_dim_vect_ibfr (ident_vect);
|
||||
CGAL_assertion_msg (nb == 1, "the dimension of vector must be 1");
|
||||
ident_elt = rs_export_elt_vect_ibfr (ident_vect, 0);
|
||||
mpfi_set (x[index-1], (mpfi_ptr)rs_export_ibfr_mpfi (ident_elt));
|
||||
return nb;
|
||||
}
|
||||
|
||||
int affiche_sols_eqs (mpfi_t *&x) {
|
||||
int ident_sols_eqs, nb_elts, ident_node, ident_vect, i;
|
||||
ident_sols_eqs = rs_get_default_sols_eqs ();
|
||||
// the number of solutions
|
||||
nb_elts = rs_export_list_vect_ibfr_nb (ident_sols_eqs);
|
||||
ident_node = rs_export_list_vect_ibfr_firstnode (ident_sols_eqs);
|
||||
x = (mpfi_t *) malloc (nb_elts*sizeof(mpfi_t));
|
||||
int affiche_sols_eqs (mpfi_ptr *&x) {
|
||||
int ident_sols_eqs,nb_elts,ident_node,ident_vect,i,ident_elt;
|
||||
ident_sols_eqs=rs_get_default_sols_eqs ();
|
||||
nb_elts=rs_export_list_vect_ibfr_nb(ident_sols_eqs);
|
||||
ident_node=rs_export_list_vect_ibfr_firstnode(ident_sols_eqs);
|
||||
x=(mpfi_ptr*)malloc(nb_elts*sizeof(mpfi_ptr));
|
||||
for (i=0; i<nb_elts; ++i) {
|
||||
mpfi_init (x[i]);
|
||||
ident_vect = rs_export_list_vect_ibfr_monnode (ident_node);
|
||||
affiche_vect_ibfr (x, i+1, ident_vect);
|
||||
ident_node = rs_export_list_vect_ibfr_nextnode (ident_node);
|
||||
ident_vect=rs_export_list_vect_ibfr_monnode(ident_node);
|
||||
CGAL_assertion_msg(rs_export_dim_vect_ibfr(ident_vect)==1,
|
||||
"the dimension of vector must be 1");
|
||||
ident_elt=rs_export_elt_vect_ibfr(ident_vect,0);
|
||||
x[i]=(mpfi_ptr)rs_export_ibfr_mpfi(ident_elt);
|
||||
ident_node=rs_export_list_vect_ibfr_nextnode(ident_node);
|
||||
}
|
||||
return nb_elts;
|
||||
}
|
||||
|
|
@ -116,7 +108,7 @@ void create_rs_uconstr (mpz_t ** list_constr,
|
|||
rs_dappend_list_sup_bz (ident_list, ident_poly);
|
||||
}
|
||||
|
||||
int solve_1 (mpfi_t *&x, const Rational_polynomial_1 &p1, unsigned int prec) {
|
||||
int solve_1 (mpfi_ptr *&x, const Rational_polynomial_1 &p1, unsigned int prec) {
|
||||
// the solver must be initialized
|
||||
rs_reset_all ();
|
||||
create_rs_upoly
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ CGAL_BEGIN_NAMESPACE
|
|||
int init_solver ();
|
||||
|
||||
// solve given the precision, returns de number of roots
|
||||
int solve_1 (mpfi_t *&, const Rational_polynomial_1 &,
|
||||
int solve_1 (mpfi_ptr *&, const Rational_polynomial_1 &,
|
||||
unsigned int = CGAL_RS_DEF_PREC);
|
||||
|
||||
// evaluate a polynomial at a given algebraic number
|
||||
|
|
|
|||
Loading…
Reference in New Issue