diff --git a/.gitattributes b/.gitattributes index 669334f9239..4565b0a391c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -200,6 +200,20 @@ Apollonius_graph_2/doc_tex/Apollonius_graph_2_ref/insert_degree_2.fig -text svne Apollonius_graph_2/doc_tex/Apollonius_graph_2_ref/insert_degree_2.gif -text svneol=unset#image/gif Apollonius_graph_2/doc_tex/Apollonius_graph_2_ref/insert_degree_2.png -text svneol=unset#image/png Approximate_min_ellipsoid_d/documentation/boundingbox.mw -text svneol=native#application/octet-stream +Arithmetic_kernel/include/CGAL/Arithmetic_kernel/Arithmetic_kernel_base.h -text +Arithmetic_kernel/include/CGAL/CORE_arithmetic_kernel.h -text +Arithmetic_kernel/include/CGAL/GMP_arithmetic_kernel.h -text +Arithmetic_kernel/include/CGAL/Get_arithmetic_kernel.h -text +Arithmetic_kernel/include/CGAL/LEDA_arithmetic_kernel.h -text +Arithmetic_kernel/include/CGAL/OLD/GMP/Gmpfr_interval_type.h -text +Arithmetic_kernel/include/CGAL/OLD/Gmpfr_interval.h -text +Arithmetic_kernel/test/Arithmetic_kernel/Arithmetic_kernel.cpp -text +Arithmetic_kernel/test/Arithmetic_kernel/CMakeLists.txt -text +Arithmetic_kernel/test/Arithmetic_kernel/CORE_arithmetic_kernel.cpp -text +Arithmetic_kernel/test/Arithmetic_kernel/GMP_arithmetic_kernel.cpp -text +Arithmetic_kernel/test/Arithmetic_kernel/LEDA_arithmetic_kernel.cpp -text +Arithmetic_kernel/test/Arithmetic_kernel/OLD/Gmpfr_interval.cpp -text +Arithmetic_kernel/test/Arithmetic_kernel/include/CGAL/Test/_test_arithmetic_kernel.h -text Arrangement_on_surface_2/benchmarks/data/benchArrAosConics.xml svneol=native#text/xml Arrangement_on_surface_2/benchmarks/data/benchArrAosPolylines.xml svneol=native#text/xml Arrangement_on_surface_2/benchmarks/data/benchArrAosSegments.xml svneol=native#text/xml diff --git a/Arithmetic_kernel/include/CGAL/Arithmetic_kernel.h b/Arithmetic_kernel/include/CGAL/Arithmetic_kernel.h new file mode 100644 index 00000000000..647d2dd93de --- /dev/null +++ b/Arithmetic_kernel/include/CGAL/Arithmetic_kernel.h @@ -0,0 +1,75 @@ +// Copyright (c) 2008-2009 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; version 2.1 of the License. +// See the file LICENSE.LGPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Michael Hemmer +// +// ============================================================================ +// +// \brief provide class Arithmetic_kernel, a collection of number types. +// + +// + +/*! \file CGAL/Arithmetic_kernel.h + * \brief Declarations pertaining to CGAL::Arithmetic_kernel + */ + +#ifndef CGAL_ARITHMETIC_KERNEL_H +#define CGAL_ARITHMETIC_KERNEL_H + +#include +#include +#include +#include + + +// Define a default Arithmetic_kernel GMP, CORE, LEDA + +namespace CGAL{ + +#ifndef CGAL_HAVE_DEFAULT_ARITHMETIC_KERNEL +#if defined(CGAL_HAVE_LEDA_ARITHMETIC_KERNEL) +typedef LEDA_arithmetic_kernel Arithmetic_kernel; +#define CGAL_HAVE_DEFAULT_ARITHMETIC_KERNEL 1 +#endif // CGAL_USE_LEDA +#endif // CGAL_HAVE_DEFAULT_ARITHMETIC_KERNEL + +#ifndef CGAL_HAVE_DEFAULT_ARITHMETIC_KERNEL +#if defined(CGAL_HAVE_GMP_ARITHMETIC_KERNEL) +typedef GMP_arithmetic_kernel Arithmetic_kernel; +#define CGAL_HAVE_DEFAULT_ARITHMETIC_KERNEL 1 +#endif // CGAL_USE_GMP +#endif // CGAL_HAVE_DEFAULT_ARITHMETIC_KERNEL + +#ifndef CGAL_HAVE_DEFAULT_ARITHMETIC_KERNEL +#if defined(CGAL_HAVE_LEDA_ARITHMETIC_KERNEL) +typedef CORE_arithmetic_kernel Arithmetic_kernel; +#define CGAL_HAVE_DEFAULT_ARITHMETIC_KERNEL 1 +#endif // CGAL_USE_CORE +#endif // CGAL_HAVE_DEFAULT_ARITHMETIC_KERNEL + +} // namespace CGAL + + +// Macro to snap typedefs in Arithmetic_kernel +#define CGAL_SNAP_ARITHMETIC_KERNEL_TYPEDEFS(AT) \ + typedef typename AT::Integer Integer; \ + typedef typename AT::Rational Rational; \ + typedef typename AT::Field_with_sqrt Field_with_sqrt; + +#endif // CGAL_ARITHMETIC_KERNEL_H +// EOF diff --git a/Arithmetic_kernel/include/CGAL/Arithmetic_kernel/Arithmetic_kernel_base.h b/Arithmetic_kernel/include/CGAL/Arithmetic_kernel/Arithmetic_kernel_base.h new file mode 100644 index 00000000000..8d4b45b642f --- /dev/null +++ b/Arithmetic_kernel/include/CGAL/Arithmetic_kernel/Arithmetic_kernel_base.h @@ -0,0 +1,48 @@ +// Copyright (c) 2006-2009 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; version 2.1 of the License. +// See the file LICENSE.LGPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL:$ +// $Id:$ +// +// Author(s) : Michael Hemmer +// +// ============================================================================ +// +// \brief provide base class for Arithmetic_kernel +// + + + +#ifndef CGAL_ARITHMETIC_KERNEL_ARITHMETIC_KERNEL_BASE_H +#define CGAL_ARITHMETIC_KERNEL_ARITHMETIC_KERNEL_BASE_H + +CGAL_BEGIN_NAMESPACE +namespace internal{ + +class Arithmetic_kernel_base{ +public: + typedef CGAL::Null_tag Integer; + typedef CGAL::Null_tag Rational; + typedef CGAL::Null_tag Field_with_sqrt; + typedef CGAL::Null_tag Field_with_kth_root; + typedef CGAL::Null_tag Field_with_root_of; + typedef CGAL::Null_tag Bigfloat; + typedef CGAL::Null_tag Bigfloat_interval; +// typedef CGAL::Null_tag Exact_float_number; +}; + +}// namespace internal +CGAL_END_NAMESPACE + +#endif // CGAL_ARITHMETIC_KERNEL_ARITHMETIC_KERNEL_BASE_H diff --git a/Arithmetic_kernel/include/CGAL/CORE_arithmetic_kernel.h b/Arithmetic_kernel/include/CGAL/CORE_arithmetic_kernel.h new file mode 100644 index 00000000000..2107362ec79 --- /dev/null +++ b/Arithmetic_kernel/include/CGAL/CORE_arithmetic_kernel.h @@ -0,0 +1,88 @@ + +// Copyright (c) 2009 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; version 2.1 of the License. +// See the file LICENSE.LGPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL: svn+ssh://hemmer@scm.gforge.inria.fr/svn/cgal/branches/experimental-packages/Arithmetic_kernel/include/CGAL/Arithmetic_kernel.h $ +// $Id: Arithmetic_kernel.h 48930 2009-04-27 09:40:56Z hemmer $ +// +// Author(s) : Michael Hemmer +// +// ============================================================================ +// +// \brief provide class LEDA_arithmetic_kernel, a collection of number types. +// + + + +#ifndef CGAL_CORE_ARITHMETIC_KERNEL_H +#define CGAL_CORE_ARITHMETIC_KERNEL_H + +#include + +#ifdef CGAL_USE_CORE + +#define CGAL_HAVE_CORE_ARITHMETIC_KERNEL + +#include +#include + +#include +#include +#include +#include + +CGAL_BEGIN_NAMESPACE + +/*! \ingroup CGAL_Arithmetic_kernel + * \brief The CORE set of exact number types + */ +class CORE_arithmetic_kernel : public internal::Arithmetic_kernel_base { +public: + //! exact integers + typedef CORE::BigInt Integer; + //! exact float nummber + typedef CORE::BigRat Exact_float_number; + //! exact rationals, constructible from integers + typedef CORE::BigRat Rational; + //! exact root expressions, constructible from integers and rationals + typedef CORE::Expr Field_with_sqrt; + // undocumented + //typedef CORE::BigFloat Bigfloat; + typedef CORE::BigFloat Bigfloat_interval; + +}; + + +template <> +struct Get_arithmetic_kernel{ + typedef CORE_arithmetic_kernel Arithmetic_kernel; +}; +template <> +struct Get_arithmetic_kernel{ + typedef CORE_arithmetic_kernel Arithmetic_kernel; +}; +template <> +struct Get_arithmetic_kernel{ + typedef CORE_arithmetic_kernel Arithmetic_kernel; +}; +template <> +struct Get_arithmetic_kernel{ + typedef CORE_arithmetic_kernel Arithmetic_kernel; +}; + +CGAL_END_NAMESPACE + +#endif // CGAL_USE_CORE + +#endif // CGAL_CORE_ARITHMETIC_KERNEL_H diff --git a/Arithmetic_kernel/include/CGAL/GMP_arithmetic_kernel.h b/Arithmetic_kernel/include/CGAL/GMP_arithmetic_kernel.h new file mode 100644 index 00000000000..beb41ccae97 --- /dev/null +++ b/Arithmetic_kernel/include/CGAL/GMP_arithmetic_kernel.h @@ -0,0 +1,83 @@ +// Copyright (c) 2008 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; version 2.1 of the License. +// See the file LICENSE.LGPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL: svn+ssh://hemmer@scm.gforge.inria.fr/svn/cgal/trunk/Number_types/include/CGAL/Arithmetic_kernel.h $ +// $Id: Arithmetic_kernel.h 47259 2008-12-06 21:47:11Z afabri $ +// +// Author(s) : Michael Hemmer +// +// ============================================================================ +// +// \brief provide class Arithmetic_kernel, a collection of number types. +// + +/*! \file CGAL/Arithmetic_kernel.h + * \brief Declarations pertaining to CGAL::Arithmetic_kernel + */ + +#ifndef CGAL_GMP_ARITHMETIC_KERNEL_H +#define CGAL_GMP_ARITHMETIC_KERNEL_H + +#include +#include +#include + + +#ifdef CGAL_USE_GMP +#ifdef CGAL_USE_MPFI + +#define CGAL_HAVE_GMP_ARITHMETIC_KERNEL + +#include +#include +#include +#include + +CGAL_BEGIN_NAMESPACE + +/*! \ingroup CGAL_Arithmetic_kernel + * \brief The GMP set of exact number types + */ +class GMP_arithmetic_kernel : public internal::Arithmetic_kernel_base { +public: + typedef CGAL::Gmpz Integer; + typedef CGAL::Gmpq Rational; + typedef CGAL::Gmpfr Bigfloat; + typedef CGAL::Gmpfi Bigfloat_interval; +}; + +template <> +struct Get_arithmetic_kernel { + typedef GMP_arithmetic_kernel Arithmetic_kernel; +}; +template <> +struct Get_arithmetic_kernel{ + typedef GMP_arithmetic_kernel Arithmetic_kernel; +}; +template <> +struct Get_arithmetic_kernel{ + typedef GMP_arithmetic_kernel Arithmetic_kernel; +}; +template <> +struct Get_arithmetic_kernel{ + typedef GMP_arithmetic_kernel Arithmetic_kernel; +}; + +#endif //CGAL_USE_MPFI +#endif //CGAL_USE_GMP + +CGAL_END_NAMESPACE + +#endif // CGAL_ARITHMETIC_KERNEL_H +// EOF diff --git a/Arithmetic_kernel/include/CGAL/Get_arithmetic_kernel.h b/Arithmetic_kernel/include/CGAL/Get_arithmetic_kernel.h new file mode 100644 index 00000000000..c110bde7faf --- /dev/null +++ b/Arithmetic_kernel/include/CGAL/Get_arithmetic_kernel.h @@ -0,0 +1,49 @@ +// Copyright (c) 2006-2009 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; version 2.1 of the License. +// See the file LICENSE.LGPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL:$ +// $Id:$ +// +// Author(s) : Michael Hemmer +// +// ============================================================================ +// +// \brief provide base class for Get_arithmetic_kernel +// + +#ifndef CGAL_GET_ARITHMETIC_KERNEL_H +#define CGAL_GET_ARITHMETIC_KERNEL_H + +#include + +CGAL_BEGIN_NAMESPACE +template< class NT > struct Get_arithmetic_kernel; + +template class Sqrt_extension; +template +struct Get_arithmetic_kernel >{ + typedef Get_arithmetic_kernel GET; + typedef typename GET::Arithmetic_kernel Arithmetic_kernel; +}; + +template class Polynomial; +template +struct Get_arithmetic_kernel >{ + typedef Get_arithmetic_kernel GET; + typedef typename GET::Arithmetic_kernel Arithmetic_kernel; +}; + +CGAL_END_NAMESPACE + +#endif // CGAL_GET_ARITHMETIC_KERNEL_H diff --git a/Arithmetic_kernel/include/CGAL/LEDA_arithmetic_kernel.h b/Arithmetic_kernel/include/CGAL/LEDA_arithmetic_kernel.h new file mode 100644 index 00000000000..f2811b9aa3f --- /dev/null +++ b/Arithmetic_kernel/include/CGAL/LEDA_arithmetic_kernel.h @@ -0,0 +1,93 @@ +// Copyright (c) 2009 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; version 2.1 of the License. +// See the file LICENSE.LGPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL: svn+ssh://hemmer@scm.gforge.inria.fr/svn/cgal/branches/experimental-packages/Arithmetic_kernel/include/CGAL/Arithmetic_kernel.h $ +// $Id: Arithmetic_kernel.h 48930 2009-04-27 09:40:56Z hemmer $ +// +// Author(s) : Michael Hemmer +// +// ============================================================================ +// +// \brief provide class LEDA_arithmetic_kernel, a collection of number types. +// + + +#ifndef CGAL_LEDA_ARITHMETIC_KERNEL_H +#define CGAL_LEDA_ARITHMETIC_KERNEL_H + +#include + +#ifdef CGAL_USE_LEDA + +#define CGAL_HAVE_LEDA_ARITHMETIC_KERNEL + +#include +#include + +#include +#include +#include +#include +#include + + +CGAL_BEGIN_NAMESPACE + +/*! \ingroup CGAL_Arithmetic_kernel + * \brief The LEDA set of exact number types + */ +class LEDA_arithmetic_kernel : public internal::Arithmetic_kernel_base { +public: + //! exact integers + typedef leda_integer Integer; + //! exact rationals, constructible from integers + typedef leda_rational Rational; + //! exact root expressions, constructible from integers and rationals + typedef leda_real Field_with_sqrt; + + // undocumented + typedef leda_bigfloat Bigfloat; + typedef leda_bigfloat_interval Bigfloat_interval; + +}; + + + +template <> +struct Get_arithmetic_kernel { + typedef LEDA_arithmetic_kernel Arithmetic_kernel; +}; +template <> +struct Get_arithmetic_kernel{ + typedef LEDA_arithmetic_kernel Arithmetic_kernel; +}; +template <> +struct Get_arithmetic_kernel{ + typedef LEDA_arithmetic_kernel Arithmetic_kernel; +}; +template <> +struct Get_arithmetic_kernel{ + typedef LEDA_arithmetic_kernel Arithmetic_kernel; +}; +template <> +struct Get_arithmetic_kernel{ + typedef LEDA_arithmetic_kernel Arithmetic_kernel; +}; + +CGAL_END_NAMESPACE + + +#endif // CGAL_USE_LEDA + +#endif // CGAL_LEDA_ARITHMETIC_KERNEL_H diff --git a/Arithmetic_kernel/include/CGAL/OLD/GMP/Gmpfr_interval_type.h b/Arithmetic_kernel/include/CGAL/OLD/GMP/Gmpfr_interval_type.h new file mode 100644 index 00000000000..faef0c3230b --- /dev/null +++ b/Arithmetic_kernel/include/CGAL/OLD/GMP/Gmpfr_interval_type.h @@ -0,0 +1,166 @@ +// TODO: add sign to RET + + +#ifndef CGAL_GMPFR_INTERVAL_TYPE_H +#define CGAL_GMPFR_INTERVAL_TYPE_H + +#include +#include +#include + +#define OP(o,d) Gmpfr r; \ + mpfr_ ## o (r.fr(), a.fr(), b.fr(), GMP_RND ## d); \ + return r; + +CGAL_BEGIN_NAMESPACE + +namespace internal { + +struct Rounding_for_gmpfr { +private: typedef CGAL::Gmpfr T; +public: + Rounding_for_gmpfr(){}; + ~Rounding_for_gmpfr(){}; + + T conv_down(const T& a){ // TODO: fix this + return add_down(T(0),a); + }; + T conv_up (const T& a){ // TODO: fix this + return add_up(T(0),a); + }; + // mathematical operations + T add_down(const T& a, const T& b) { + OP(add,D); + }; + T add_up (const T& a, const T& b){ + OP(add,U); + }; + T sub_down(const T& a, const T& b){ + OP(sub,D); + }; + T sub_up (const T& a, const T& b){ + OP(sub,U); + }; + T mul_down(const T& a, const T& b){ + OP(mul,D); + }; + T mul_up (const T& a, const T& b){ + OP(mul,U); + }; + T div_down(const T& a, const T& b){ + OP(div,D); + }; + T div_up (const T& a, const T& b){ + OP(div,U); + }; + + T sqrt_down(const T& a){ + T b; + mpfr_sqrt(b.fr(), a.fr(), GMP_RNDD); + return b; + }; + T sqrt_up (const T& a){ + T b; + mpfr_sqrt(b.fr(), a.fr(), GMP_RNDU); + return b; + }; + + T median(const T& a, const T& b) { + T result(a + (b-a)/2); + CGAL_postcondition(a <= result); + CGAL_postcondition(result <= b); + return result; + }; + T int_down(const T& a) { + T r; + mpfr_floor(r.fr(), a.fr()); + return r; + }; + T int_up (const T& a) { + T r; + mpfr_ceil(r.fr(), a.fr()); + return r; + }; +}; + +class Checking_for_gmpfr { + + typedef CGAL::Gmpfr T; + +public: + + static T pos_inf() { + T b; + mpfr_set_inf(b.fr(), 1); + return b; + } + + static T neg_inf() { + T b; + mpfr_set_inf(b.fr(), -1); + return b; + } + + static T nan() { + T b; + mpfr_set_nan(b.fr()); + return b; + } + + static bool is_nan(const T& b) { + return mpfr_nan_p(b.fr()); + } + + static T empty_lower() { + return T(1); + } + + static T empty_upper() { + return T(0); + } + + static bool is_empty(const T& a, const T& b) { +// return a==T(1) && b == T(0); +// return false; + return a > b; // TODO: optimize this + } +}; + +} // namespace internal +CGAL_END_NAMESPACE + +namespace boost { +namespace numeric { +inline +std::ostream& operator << + (std::ostream& os, const boost::numeric::interval& x) +{ + os << "[" + << x.lower() << ", " << x.upper() << "]"; + return os; +} + + +}//namespace numeric +}//namespace boost + +CGAL_BEGIN_NAMESPACE + +typedef boost::numeric::interval< + Gmpfr, + boost::numeric::interval_lib::policies + < internal::Rounding_for_gmpfr, internal::Checking_for_gmpfr > > +Gmpfr_interval; + +// I have to redfine these operators, since the test reports an +// ambiguity with operators in CGAL::Polynomial +// However, it seems that this is due to the use of struct interval_holder +// in the definition of the operators in boost. + +inline bool operator == (const Gmpfr_interval& x , const Gmpfr_interval& y) +{return x.operator==(y) ;} + +CGAL_END_NAMESPACE +//#endif // CGAL_USE_LEDA +#undef OP +#endif // CGAL_GMPFR_INTERVAL_TYPE_H diff --git a/Arithmetic_kernel/include/CGAL/OLD/Gmpfr_interval.h b/Arithmetic_kernel/include/CGAL/OLD/Gmpfr_interval.h new file mode 100644 index 00000000000..91c2240bc75 --- /dev/null +++ b/Arithmetic_kernel/include/CGAL/OLD/Gmpfr_interval.h @@ -0,0 +1,336 @@ +// Copyright (c) 2008 Max-Planck-Institute Saarbruecken (Germany), +// National University of Athens (Greece). +// Copyright (c) 2009 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; version 2.1 of the License. +// See the file LICENSE.LGPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL:$ +// $Id:$ +// +// Author(s) : George Tzoumas , +// Michael Hemmer +// +// ============================================================================ +// +// \brief provide CGAL support for class CGAL::Gmpfr_interval. +// + +#ifndef CGAL_GMPFR_INTERVAL_H +#define CGAL_GMPFR_INTERVAL_H + +#include +#include +#include +#include +#include +#include +#include + +CGAL_BEGIN_NAMESPACE + +template <> class Algebraic_structure_traits< Gmpfr_interval > + : public Algebraic_structure_traits_base < Gmpfr_interval, + Field_with_sqrt_tag >{ + +public: + typedef Tag_false Is_exact; + typedef Tag_true Is_numerical_sensitive; + + class Sqrt + : public std::unary_function< Type, Type > { + public: + Type operator()( const Type& x ) const { + return ::boost::numeric::sqrt(x); + } + }; +}; + +template <> class Real_embeddable_traits< Gmpfr_interval > + : public INTERN_RET::Real_embeddable_traits_base { +public: + + class Abs + : public std::unary_function< Type, Type > { + public: + Type operator()( const Type& x ) const { + return ::boost::numeric::abs(x); + } + }; + + class To_double + : public std::unary_function< Type, double > { + public: + double operator()( const Type& x ) const { + return ::boost::numeric::median(x).to_double(); + } + }; + + class To_interval + : public std::unary_function< Type, std::pair< double, double > > { + public: + std::pair operator()( const Type& x ) const { + std::pair lower_I(x.lower().to_interval()); + std::pair upper_I(x.upper().to_interval()); + return std::pair< double, double >( + (CGAL::min)(lower_I.first , upper_I.first ), + (CGAL::max)(lower_I.second, upper_I.second)); + } + }; +}; + +template<> +class Interval_traits +{ +public: + typedef Interval_traits Self; + typedef Gmpfr_interval Interval; + typedef CGAL::Gmpfr Bound; + typedef CGAL::Tag_true With_empty_interval; + typedef CGAL::Tag_true Is_interval; + + struct Construct :public std::binary_function{ + Interval operator()( const Bound& l,const Bound& r) const { + CGAL_precondition( l < r ); + return Interval(l,r); + } + }; + + struct Lower :public std::unary_function{ + Bound operator()( const Interval& a ) const { + return a.lower(); + } + }; + + struct Upper :public std::unary_function{ + Bound operator()( const Interval& a ) const { + return a.upper(); + } + }; + + struct Width :public std::unary_function{ + Bound operator()( const Interval& a ) const { + return ::boost::numeric::width(a); + } + }; + + struct Median :public std::unary_function{ + Bound operator()( const Interval& a ) const { + return ::boost::numeric::median(a); + } + }; + + struct Norm :public std::unary_function{ + Bound operator()( const Interval& a ) const { + return ::boost::numeric::norm(a); + } + }; + + struct Empty :public std::unary_function{ + bool operator()( const Interval& a ) const { + return ::boost::numeric::empty(a); + } + }; + + struct Singleton :public std::unary_function{ + bool operator()( const Interval& a ) const { + return ::boost::numeric::singleton(a); + } + }; + + struct Zero_in :public std::unary_function{ + bool operator()( const Interval& a ) const { + return ::boost::numeric::in_zero(a); + } + }; + + struct In :public std::binary_function{ + bool operator()( Bound x, const Interval& a ) const { + return ::boost::numeric::in(x,a); + } + }; + + struct Equal :public std::binary_function{ + bool operator()( const Interval& a, const Interval& b ) const { + return ::boost::numeric::equal(a,b); + } + }; + + struct Overlap :public std::binary_function{ + bool operator()( const Interval& a, const Interval& b ) const { + return ::boost::numeric::overlap(a,b); + } + }; + + struct Subset :public std::binary_function{ + bool operator()( const Interval& a, const Interval& b ) const { + return ::boost::numeric::subset(a,b); + } + }; + + struct Proper_subset :public std::binary_function{ + bool operator()( const Interval& a, const Interval& b ) const { + return ::boost::numeric::proper_subset(a,b); + } + }; + + struct Hull :public std::binary_function{ + Interval operator()( const Interval& a, const Interval& b ) const { + return ::boost::numeric::hull(a,b); + } + }; + + struct Intersection :public std::binary_function{ + Interval operator()( const Interval& a, const Interval& b ) const { + Interval r = ::boost::numeric::intersect(a,b); + return r; + } + }; +}; + +template<> +class Bigfloat_interval_traits: + public Interval_traits +{ +public: + typedef Gmpfr_interval NT; + + typedef CGAL::Gmpfr BF; + + struct Get_significant_bits: public std::unary_function{ + + long operator()( NT x) const { + if(CGAL::zero_in(x)) return -1; + BF labs = CGAL::lower(CGAL::abs(x)) ; + BF w = CGAL::width(x); + BF err; + mpfr_div(err.fr(), w.fr(), labs.fr(), GMP_RNDU); + mpfr_log2(err.fr(), err.fr(), GMP_RNDD); + return -mpfr_get_si(err.fr(), GMP_RNDU); + } + }; + + struct Set_precision { + // type for the \c AdaptableUnaryFunction concept. + typedef long argument_type; + // type for the \c AdaptableUnaryFunction concept. + typedef long result_type; + + long operator()( long prec ) const { + long old_prec = mpfr_get_default_prec(); +// std::cerr << "precision set to " << prec << " from " << old_prec << std::endl; + mpfr_set_default_prec(prec); + return old_prec; + } + }; + + struct Get_precision { + // type for the \c AdaptableGenerator concept. + typedef long result_type; + long operator()() const { + return mpfr_get_default_prec(); + } + }; + +}; + +//Gmp internal coercions: +CGAL_DEFINE_COERCION_TRAITS_FOR_SELF(Gmpfr_interval) + +// The following definitions reflect the interaction of the Gmpfr + +// built in types : + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,Gmpfr_interval) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,Gmpfr_interval) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,Gmpfr_interval) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,Gmpfr_interval) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,Gmpfr_interval) + + +template <> +struct Coercion_traits{ + typedef Tag_true Are_explicit_interoperable; + typedef Tag_false Are_implicit_interoperable; + typedef CGAL::Gmpfr_interval Type; + + struct Cast{ + typedef Type result_type; + Type operator()(const CGAL::Gmpfr_interval& x) const { return x;} + Type operator()(const CGAL::Gmpz x) const { + CGAL::Gmpfr lower, upper; + mpfr_set_z (lower.fr(), x.mpz(), GMP_RNDD); + mpfr_set_z (upper.fr(), x.mpz(), GMP_RNDU); + Type bfi(lower, upper); + CGAL_postcondition( bfi.lower() <= x ); + CGAL_postcondition( bfi.upper() >= x ); + return bfi; + } + }; +}; + +template <> // mirror +struct Coercion_traits + :public Coercion_traits{}; + +template <> +struct Coercion_traits{ + typedef Tag_true Are_explicit_interoperable; + typedef Tag_false Are_implicit_interoperable; + typedef CGAL::Gmpfr_interval Type; + typedef Coercion_traits CTZ; + + struct Cast{ + typedef Type result_type; + Type operator()(const CGAL::Gmpfr_interval& x) const { return x;} + Type operator()(const CGAL::Gmpq x) const { + // early exits + if (CGAL::is_zero(x)) return Type(0,0); + if (CGAL::is_one(x.denominator())){ + return CTZ::Cast()(x.numerator()); + } + // TODO: ensure that prec is reached for resulting interval ? + Gmpfr lower, upper, nf, df; + CGAL::Gmpz num = x.numerator(); + CGAL::Gmpz den = x.denominator(); + mp_prec_t prec = mpfr_get_default_prec(); + CGAL_assertion( mpfr_get_prec(lower.fr()) == prec); + CGAL_assertion( mpfr_get_prec(upper.fr()) == prec ); + + mpfr_set_z (nf.fr(), num.mpz(), GMP_RNDD); + mpfr_set_z (df.fr(), den.mpz(), + (CGAL::sign(num) == CGAL::NEGATIVE)? GMP_RNDD: GMP_RNDU); + mpfr_div(lower.fr(), nf.fr(), df.fr(), GMP_RNDD); + + mpfr_set_z (nf.fr(), num.mpz(), GMP_RNDU); + mpfr_set_z (df.fr(), den.mpz(), + (CGAL::sign(num) == CGAL::NEGATIVE)? GMP_RNDU: GMP_RNDD); + mpfr_div(upper.fr(), nf.fr(), df.fr(), GMP_RNDU); + + Type bfi(lower, upper); + + CGAL_postcondition( bfi.lower() <= x ); + CGAL_postcondition( bfi.upper() >= x ); + return bfi; + } + }; +}; + +template <> // mirror +struct Coercion_traits + :public Coercion_traits{}; + + +// lower GMP types: +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(Gmpfr,Gmpfr_interval) + +CGAL_END_NAMESPACE +#endif // CGAL_GMPFR_INTERVAL_H diff --git a/Arithmetic_kernel/test/Arithmetic_kernel/Arithmetic_kernel.cpp b/Arithmetic_kernel/test/Arithmetic_kernel/Arithmetic_kernel.cpp new file mode 100644 index 00000000000..87c8376cc72 --- /dev/null +++ b/Arithmetic_kernel/test/Arithmetic_kernel/Arithmetic_kernel.cpp @@ -0,0 +1,18 @@ +#include +#include +#include + +#if defined(CGAL_HAVE_DEFAULT_ARITHMETIC_KERNEL) + +#include + +int main() { + + typedef CGAL::Arithmetic_kernel AK; + CGAL::test_arithmetic_kernel(); + return 0; +} + +#else +int main() { return 0; } +#endif diff --git a/Arithmetic_kernel/test/Arithmetic_kernel/CMakeLists.txt b/Arithmetic_kernel/test/Arithmetic_kernel/CMakeLists.txt new file mode 100644 index 00000000000..541e6f297f6 --- /dev/null +++ b/Arithmetic_kernel/test/Arithmetic_kernel/CMakeLists.txt @@ -0,0 +1,61 @@ +# Created by the script cgal_create_cmake_script +# This is the CMake script for compiling a CGAL application. + + +project( Arithmetic_kernel_test ) + +CMAKE_MINIMUM_REQUIRED(VERSION 2.4.5) + +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) + + +if ( COMMAND cmake_policy ) + cmake_policy( SET CMP0003 NEW ) +endif() + +find_package(CGAL QUIET COMPONENTS Core ) + +if ( CGAL_FOUND ) + + include( ${CGAL_USE_FILE} ) + include( CGAL_VersionUtils ) + find_package( MPFI ) + IS_VERSION_LESS("${CGAL_GMP_VERSION}" "4.2.0" _IS_GMP_VERSION_TO_LOW) + + + include_directories(../../include) + include_directories(include) + include_directories($ENV{CGAL}/trunk/Number_types/include/) + include_directories($ENV{CGAL}/trunk/Algebraic_foundations/include/) + include_directories($ENV{CGAL}/trunk/Modular_arithmetic/include/) + include_directories($ENV{CGAL}/trunk/Polynomial/include/) + include_directories($ENV{CGAL}/trunk/Number_types/test/Number_types/include/) + + include( CGAL_CreateSingleSourceCGALProgram ) + + create_single_source_cgal_program( "Arithmetic_kernel.cpp" ) + create_single_source_cgal_program( "CORE_arithmetic_kernel.cpp" ) + create_single_source_cgal_program( "LEDA_arithmetic_kernel.cpp" ) + + if( MPFI_FOUND ) + # for the testsuite, the version of MPFI shipped with RS is used; this + # version needs GMP>=4.2, so we require this dependency only here and + # not in FindMPFI.cmake + if( _IS_GMP_VERSION_TO_LOW ) + message( STATUS + "MPFI tests need GMP>=4.2, some of the tests will not be compiled" ) + else( _IS_GMP_VERSION_TO_LOW ) + include( ${MPFI_USE_FILE} ) + create_single_source_cgal_program( "GMP_arithmetic_kernel.cpp" ) + endif( _IS_GMP_VERSION_TO_LOW ) + else( MPFI_FOUND ) + message( STATUS + "MPFI is not present, some of the tests will not be compiled." ) + endif( MPFI_FOUND ) + +else() + + message(STATUS "This program requires the CGAL library, and will not be compiled.") + +endif() + diff --git a/Arithmetic_kernel/test/Arithmetic_kernel/CORE_arithmetic_kernel.cpp b/Arithmetic_kernel/test/Arithmetic_kernel/CORE_arithmetic_kernel.cpp new file mode 100644 index 00000000000..84b013e29e7 --- /dev/null +++ b/Arithmetic_kernel/test/Arithmetic_kernel/CORE_arithmetic_kernel.cpp @@ -0,0 +1,17 @@ +#include +#include + +#include + +#ifdef CGAL_HAVE_CORE_ARITHMETIC_KERNEL +#include + +int main() { + typedef CGAL::CORE_arithmetic_kernel AK; + CGAL::test_arithmetic_kernel(); + return 0; +} + +#else +int main() { return 0; } +#endif diff --git a/Arithmetic_kernel/test/Arithmetic_kernel/GMP_arithmetic_kernel.cpp b/Arithmetic_kernel/test/Arithmetic_kernel/GMP_arithmetic_kernel.cpp new file mode 100644 index 00000000000..e3d83a9d235 --- /dev/null +++ b/Arithmetic_kernel/test/Arithmetic_kernel/GMP_arithmetic_kernel.cpp @@ -0,0 +1,18 @@ +#include +#include +#include + +#ifdef CGAL_HAVE_GMP_ARITHMETIC_KERNEL + +#include + +int main() { + std::cout << "TEST GMP_arithmetic_kernel" << std::endl; + typedef CGAL::GMP_arithmetic_kernel AK; + CGAL::test_arithmetic_kernel(); + return 0; +} + +#else +int main() { return 0; } +#endif diff --git a/Arithmetic_kernel/test/Arithmetic_kernel/LEDA_arithmetic_kernel.cpp b/Arithmetic_kernel/test/Arithmetic_kernel/LEDA_arithmetic_kernel.cpp new file mode 100644 index 00000000000..1c92efe8866 --- /dev/null +++ b/Arithmetic_kernel/test/Arithmetic_kernel/LEDA_arithmetic_kernel.cpp @@ -0,0 +1,17 @@ +#include +#include +#include + +#ifdef CGAL_HAVE_LEDA_ARITHMETIC_KERNEL + +#include + +int main() { + typedef CGAL::LEDA_arithmetic_kernel AK; + CGAL::test_arithmetic_kernel(); + return 0; +} + +#else +int main() { return 0; } +#endif diff --git a/Arithmetic_kernel/test/Arithmetic_kernel/OLD/Gmpfr_interval.cpp b/Arithmetic_kernel/test/Arithmetic_kernel/OLD/Gmpfr_interval.cpp new file mode 100644 index 00000000000..d5122add88e --- /dev/null +++ b/Arithmetic_kernel/test/Arithmetic_kernel/OLD/Gmpfr_interval.cpp @@ -0,0 +1,33 @@ +#include +#include +#ifdef CGAL_HAVE_GMP_ARITHMETIC_KERNEL +#include +#include +#include +#include + +int main() { + std::cout << "TEST Gmpfr_interval "; std::cout.flush(); + typedef CGAL::Gmpfr_interval NT; + typedef CGAL::Field_with_sqrt_tag Tag; + typedef CGAL::Tag_false Is_exact; + CGAL::test_algebraic_structure(); + CGAL::test_algebraic_structure(NT(4),NT(6),NT(15)); + CGAL::test_algebraic_structure(NT(-4),NT(6),NT(15)); + CGAL::test_algebraic_structure(NT(4),NT(-6),NT(15)); + CGAL::test_algebraic_structure(NT(-4),NT(-6),NT(15)); + CGAL::test_algebraic_structure(NT(4),NT(6),NT(-15)); + CGAL::test_algebraic_structure(NT(-4),NT(6), NT(15)); + CGAL::test_algebraic_structure(NT(4),NT(-6),NT(-15)); + CGAL::test_algebraic_structure(NT(-4),NT(-6),NT(-15)); + + CGAL::test_real_embeddable(); + CGAL::test_interval(); + + std::cout << "OK" << std::endl; + return 0; +} + +#else +int main() { return 0; } +#endif diff --git a/Arithmetic_kernel/test/Arithmetic_kernel/include/CGAL/Test/_test_arithmetic_kernel.h b/Arithmetic_kernel/test/Arithmetic_kernel/include/CGAL/Test/_test_arithmetic_kernel.h new file mode 100644 index 00000000000..3f79384d8cc --- /dev/null +++ b/Arithmetic_kernel/test/Arithmetic_kernel/include/CGAL/Test/_test_arithmetic_kernel.h @@ -0,0 +1,126 @@ +// Copyright (c) 2006-2009 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; version 2.1 of the License. +// See the file LICENSE.LGPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL:$ +// $Id:$ +// +// Author(s) : Michael Hemmer +// +// ============================================================================ +// +// \brief provide test for Arithmetic_kernel +// + +#ifndef CGAL_TEST_ARITHMETIC_KERNEL_H +#define CGAL_TEST_ARITHMETIC_KERNEL_H + +#include +#include + +CGAL_BEGIN_NAMESPACE + + typedef CGAL::Interval_nt Interval; + + void test_coercion_from_to(CGAL::Null_tag, CGAL::Null_tag){}; + template void test_coercion_from_to(A, CGAL::Null_tag){}; + template void test_coercion_from_to(CGAL::Null_tag, B){}; + template void test_coercion_from_to(A, B){ + CGAL::test_explicit_interoperable_from_to(); + }; + +template +void test_coercion_arithmetic_kernel(){ + + + typedef typename ARK::Integer Integer; + typedef typename ARK::Rational Rational; + typedef typename ARK::Field_with_sqrt Field_with_sqrt; + typedef typename ARK::Field_with_kth_root Field_with_kth_root; + typedef typename ARK::Field_with_root_of Field_with_root_of; + typedef typename ARK::Bigfloat Bigfloat; + typedef typename ARK::Bigfloat_interval Bigfloat_interval; + + + test_coercion_from_to(int(),Integer()); + test_coercion_from_to(short(),Integer()); + test_coercion_from_to(Integer(),Integer()); + + test_coercion_from_to(int(),Rational()); + test_coercion_from_to(short(),Rational()); + test_coercion_from_to(float(),Rational()); + test_coercion_from_to(double(),Rational()); + test_coercion_from_to(Integer(),Rational()); + // This is currently not consistent with LEDA and GMP, for CORE it is not even defined. + // test_coercion_from_to(Bigfloat(),Rational()); + test_coercion_from_to(Rational(),Rational()); + + test_coercion_from_to(int(),Field_with_sqrt()); + test_coercion_from_to(short(),Field_with_sqrt()); + test_coercion_from_to(float(),Field_with_sqrt()); + test_coercion_from_to(double(),Field_with_sqrt()); + test_coercion_from_to(Integer(),Field_with_sqrt()); + test_coercion_from_to(Bigfloat(),Field_with_sqrt()); + test_coercion_from_to(Rational(),Field_with_sqrt()); + test_coercion_from_to(Field_with_sqrt(),Field_with_sqrt()); + + test_coercion_from_to(int(),Field_with_kth_root()); + test_coercion_from_to(short(),Field_with_kth_root()); + test_coercion_from_to(float(),Field_with_kth_root()); + test_coercion_from_to(double(),Field_with_kth_root()); + test_coercion_from_to(Integer(),Field_with_kth_root()); + test_coercion_from_to(Bigfloat(),Field_with_kth_root()); + test_coercion_from_to(Rational(),Field_with_kth_root()); + test_coercion_from_to(Field_with_sqrt(),Field_with_kth_root()); + test_coercion_from_to(Field_with_kth_root(),Field_with_kth_root()); + + + test_coercion_from_to(int(),Field_with_root_of()); + test_coercion_from_to(short(),Field_with_root_of()); + test_coercion_from_to(float(),Field_with_root_of()); + test_coercion_from_to(double(),Field_with_root_of()); + test_coercion_from_to(Integer(),Field_with_root_of()); + test_coercion_from_to(Bigfloat(),Field_with_root_of()); + test_coercion_from_to(Rational(),Field_with_root_of()); + test_coercion_from_to(Field_with_sqrt(),Field_with_root_of()); + test_coercion_from_to(Field_with_kth_root(),Field_with_root_of()); + test_coercion_from_to(Field_with_root_of(),Field_with_root_of()); + + + test_coercion_from_to(int(),Bigfloat()); + test_coercion_from_to(short(),Bigfloat()); + test_coercion_from_to(float(),Bigfloat()); + test_coercion_from_to(double(),Bigfloat()); + test_coercion_from_to(Integer(),Bigfloat()); + test_coercion_from_to(Bigfloat(),Bigfloat()); + + + test_coercion_from_to(int(),Bigfloat_interval()); + test_coercion_from_to(short(),Bigfloat_interval()); + test_coercion_from_to(float(),Bigfloat_interval()); + test_coercion_from_to(double(),Bigfloat_interval()); + test_coercion_from_to(Integer(),Bigfloat_interval()); + test_coercion_from_to(Bigfloat(),Bigfloat_interval()); + test_coercion_from_to(Rational(),Bigfloat_interval()); + test_coercion_from_to(Field_with_sqrt(),Bigfloat_interval()); + test_coercion_from_to(Field_with_kth_root(),Bigfloat_interval()); + test_coercion_from_to(Field_with_root_of(),Bigfloat_interval()); + test_coercion_from_to(Bigfloat_interval(),Bigfloat_interval()); +} + +template +void test_arithmetic_kernel(){ + test_coercion_arithmetic_kernel(); +} +CGAL_END_NAMESPACE +#endif // CGAL_TEST_ARITHMETIC_KERNEL_H