1
// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved.
3
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
4
// modify it under the terms of the GNU Lesser General Public License as
5
// published by the Free Software Foundation; either version 3 of the License,
6
// or (at your option) any later version.
8
// See the file LICENSE.LGPL distributed with CGAL.
10
// Licensees holding a valid commercial license may use this file in
11
// accordance with the commercial license agreement provided with the software.
13
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
14
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19
// Author: Luis Peñaranda <luis.penaranda@gmx.com>
21
#ifndef CGAL_RS_SIGNAT_1_H
22
#define CGAL_RS_SIGNAT_1_H
24
#include <CGAL/Gmpfi.h>
25
#include <CGAL/Polynomial_traits_d.h>
26
#include "exact_signat_1.h"
27
//#include <boost/mpl/assert.hpp>
33
template <class Polynomial_,class Bound_>
35
typedef Polynomial_ Polynomial;
37
typedef CGAL::Polynomial_traits_d<Polynomial> PT;
38
typedef typename PT::Degree Degree;
40
Signat_1(const Polynomial &p):pol(p){};
41
CGAL::Sign operator()(const Bound&)const;
44
template <class Polynomial_,class Bound_>
46
Signat_1<Polynomial_,Bound_>::operator()(const Bound_ &x)const{
48
typedef Real_embeddable_traits<Bound> REtraits;
49
typedef typename REtraits::Sgn BSign;
50
//typedef Algebraic_structure_traits<Bound> AStraits;
51
// This generic signat works only when Bound_ is an exact type. For
52
// non-exact types, an implementation must be provided.
53
//BOOST_MPL_ASSERT((boost::is_same<AStraits::Is_exact,Tag_true>));
63
Signat_1<Polynomial<Gmpz>,Gmpfr>::operator()(const Gmpfr &x)const{
64
// In 32-bit systems, using Gmpfr arithmetic to perform exact
65
// evaluations can overflow. For that reason, we only use Gmpfr
66
// arithmetic in 64-bit systems.
67
#if (GMP_LIMB_BITS==64)
68
typedef ExactSignat_1<Polynomial,Gmpfr> Exact_sign;
70
typedef Signat_1<Polynomial,Gmpq> Exact_sign;
72
// This seems to work faster for small polynomials:
73
// return Exact_sign(pol)(x);
77
Gmpfi h(pol[d],x.get_precision()+2*d);
78
Uncertain<CGAL::Sign> indet=Uncertain<CGAL::Sign>::indeterminate();
79
if(h.sign().is_same(indet))
80
return Exact_sign(pol)(x);
81
for(int i=1;i<=d;++i){
84
if(h.sign().is_same(indet))
85
return Exact_sign(pol)(x);
87
CGAL_assertion(!h.sign().is_same(indet));
91
// This is the same code as above.
94
Signat_1<Polynomial<Gmpq>,Gmpfr>::operator()(const Gmpfr &x)const{
95
typedef Signat_1<Polynomial,Gmpq> Exact_sign;
99
Gmpfi h(pol[d],x.get_precision()+2*d);
100
Uncertain<CGAL::Sign> indet=Uncertain<CGAL::Sign>::indeterminate();
101
if(h.sign().is_same(indet))
102
return Exact_sign(pol)(x);
103
for(int i=1;i<=d;++i){
106
if(h.sign().is_same(indet))
107
return Exact_sign(pol)(x);
109
CGAL_assertion(!h.sign().is_same(indet));
113
} // namespace RS_AK1
116
#endif // CGAL_RS_SIGNAT_1_H