added Interval_traits and test for intervals

- boost::numeric::interval<leda::bigfloat>
- CORE::BigFloat is considered as an Interval 
adapted Coercion_traits/Arithmetik_kernel
This commit is contained in:
Michael Hemmer 2008-05-13 08:42:27 +00:00
parent 7002346ca2
commit 82fe4c5f04
15 changed files with 867 additions and 317 deletions

View File

@ -59,11 +59,25 @@
CGAL_BEGIN_NAMESPACE
namespace CGALi {
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;
};
}
#ifdef CGAL_USE_LEDA
/*! \ingroup CGAL_Arithmetic_kernel
* \brief The LEDA set of exact number types
*/
class LEDA_arithmetic_kernel {
class LEDA_arithmetic_kernel : public CGALi::Arithmetic_kernel_base {
public:
//! exact integers
typedef leda_integer Integer;
@ -85,7 +99,7 @@ public:
/*! \ingroup CGAL_Arithmetic_kernel
* \brief The CORE set of exact number types
*/
class CORE_arithmetic_kernel {
class CORE_arithmetic_kernel : public CGALi::Arithmetic_kernel_base {
public:
//! exact integers
typedef CORE::BigInt Integer;
@ -96,7 +110,7 @@ public:
//! exact root expressions, constructible from integers and rationals
typedef CORE::Expr Field_with_sqrt;
// undocumented
typedef CORE::BigFloat Bigfloat;
//typedef CORE::BigFloat Bigfloat;
typedef CORE::BigFloat Bigfloat_interval;
};
@ -106,7 +120,7 @@ public:
/*! \ingroup CGAL_Arithmetic_kernel
* \brief The GMP set of exact number types
*/
class GMP_arithmetic_kernel {
class GMP_arithmetic_kernel : public CGALi::Arithmetic_kernel_base {
public:
//! exact integers
typedef CGAL::Gmpz Integer;
@ -116,6 +130,8 @@ public:
typedef CGAL::Gmpq Rational;
//! exact root expressions, constructible from integers and rationals
typedef CGAL::Null_tag Field_with_sqrt;
typedef CGAL::Null_tag Field_with_kth_root;
typedef CGAL::Null_tag Field_with_root_of;
};
#endif // CGAL_USE_GMP
@ -123,7 +139,7 @@ public:
/*! \ingroup CGAL_Arithmetic_kernel
* \brief The GMP set of exact number types
*/
class GMPXX_arithmetic_kernel {
class GMPXX_arithmetic_kernel : public CGALi::Arithmetic_kernel_base {
public:
//! exact integers
typedef mpz_class Integer;

View File

@ -143,6 +143,8 @@ template <> class Real_embeddable_traits< CORE::BigFloat >
const Type& y ) const {
return (Comparison_result) sign( (x-y).sign());
}
CGAL_IMPLICIT_INTEROPERABLE_BINARY_OPERATOR_WITH_RT( Type,
Comparison_result );
};
class To_double
@ -179,6 +181,8 @@ template <> class Real_embeddable_traits< CORE::BigFloat >
};
};
CGAL_END_NAMESPACE
//since types are included by CORE_coercion_traits.h:

View File

@ -38,14 +38,6 @@ CGAL_BEGIN_NAMESPACE
//CORE internal coercions:
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigInt,::CORE::BigFloat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigInt,::CORE::BigRat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigInt,::CORE::Expr)
// CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigFloat,::CORE::BigRat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigFloat,::CORE::Expr)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigRat,::CORE::Expr)
// The following definitions reflect the interaction of the CORE number types
// with the built in types,
@ -56,27 +48,103 @@ CGAL_BEGIN_NAMESPACE
// CORE BigRat:
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::BigRat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::BigRat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::BigRat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::BigRat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::BigRat)
// CORE BigFloat: :
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::BigFloat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::BigFloat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::BigFloat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::BigFloat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::BigFloat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::BigRat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::BigRat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::BigRat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::BigRat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::BigRat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigInt,::CORE::BigRat)
// CORE Expr:
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::Expr)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::Expr)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::Expr)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::Expr)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::Expr)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::Expr)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::Expr)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::Expr)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::Expr)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::Expr)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigInt,::CORE::Expr)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigRat,::CORE::Expr)
// NOTE that CORE::BigFloat counts as an interval !
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::BigFloat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::BigFloat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::BigFloat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::BigFloat)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::BigFloat);
template <>
struct Coercion_traits<CORE::BigFloat , ::CORE::BigInt>{
typedef Tag_true Are_explicit_interoperable;
typedef Tag_false Are_implicit_interoperable;
typedef CORE::BigFloat Type;
struct Cast{
typedef Type result_type;
Type operator()(const CORE::BigFloat& x) const { return x;}
Type operator()(const ::CORE::BigInt x) const {
CORE::BigFloat result;
result.approx(x,CORE::defRelPrec.toLong(),1024);
// Do not use MakeFloorExact as it changes the Bigfloat
CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()-result.err(),0,result.exp())) <= x );
CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()+result.err(),0,result.exp())) >= x );
return result;
}
};
};
template <>
struct Coercion_traits<CORE::BigFloat , ::CORE::BigRat>{
typedef Tag_true Are_explicit_interoperable;
typedef Tag_false Are_implicit_interoperable;
typedef CORE::BigFloat Type;
struct Cast{
typedef Type result_type;
Type operator()(const CORE::BigFloat& x) const { return x;}
Type operator()(const ::CORE::BigRat x) const {
CORE::BigFloat result(x,CORE::defRelPrec.toLong(),1024);
// Do not use MakeFloorExact as it changes the Bigfloat
CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()-result.err(),0,result.exp())) <= x );
CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()+result.err(),0,result.exp())) >= x );
return result;
}
};
};
template <>
struct Coercion_traits<CORE::BigFloat , ::CORE::Expr>{
typedef Tag_true Are_explicit_interoperable;
typedef Tag_false Are_implicit_interoperable;
typedef CORE::BigFloat Type;
struct Cast{
typedef Type result_type;
Type operator()(const CORE::BigFloat& x) const { return x;}
Type operator()(const ::CORE::Expr x) const {
CORE::BigFloat result(x, CORE::defRelPrec.toLong(),1024);
// Do not use MakeFloorExact as it changes the Bigfloat
CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()-result.err(),0,result.exp())) <= x );
CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()+result.err(),0,result.exp())) >= x );
return result;
}
};
};
template <> struct Coercion_traits< ::CORE::BigInt, CORE::BigFloat >
:public Coercion_traits< CORE::BigFloat , ::CORE::BigInt >{};
template <> struct Coercion_traits< ::CORE::BigRat, CORE::BigFloat >
:public Coercion_traits< CORE::BigFloat , ::CORE::BigRat >{};
template <> struct Coercion_traits< ::CORE::Expr, CORE::BigFloat >
:public Coercion_traits< CORE::BigFloat , ::CORE::Expr>{};
// not provieded by CORE
// Note that this is not symmetric to LEDA

View File

@ -0,0 +1,204 @@
// TODO: Add licence
//
// 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 <hemmer@mpi-inf.mpg.de>
//
// ============================================================================
/*! \file CGAL/Interval_traits.h
This is experimental
*/
/* bounds-related Interval functions */
// template<class Interval> T lower(const Interval& x);
// template<class Interval> T upper(const Interval& x);
// template<class Interval> T width(const Interval& x);
// template<class Interval> T median(const Interval& x);
// template<class Interval> T norm(const Interval& x);
/* bounds-related Interval functions */
//// template<class Interval> bool empty(const Interval& b);
// template<class Interval> bool singleton(const Interval& x);
// template<class Interval> bool zero_in(const Interval& b);
// template<class Interval> bool in(const T& r, const Interval& b);
// template<class Interval> bool equal(const Interval& x, const Interval& y);
// template<class Interval> bool overlap(const Interval& x, const Interval& y);
// template<class Interval> bool subset(const Interval& a, const Interval& b);
// template<class Interval> bool proper_subset(const Interval& a, const Interval& b);
/* set manipulation interval functions */
// template<class Interval> Interval intersection(const Interval& x, const Interval& y);
// template<class Interval> Interval hull(const Interval& x, const Interval& y);
#ifndef CGAL_INTERVAL_TRAITS_H
#define CGAL_INTERVAL_TRAITS_H
#include <CGAL/basic.h>
#include <CGAL/basic.h>
CGAL_BEGIN_NAMESPACE
namespace CGALi{
template<typename T> struct Interval_traits_base{
typedef Interval_traits_base<T> Self;
typedef T Interval;
typedef CGAL::Null_functor Boundary;
typedef CGAL::Tag_false Is_interval;
typedef CGAL::Tag_false With_empty_interval;
typedef CGAL::Null_functor Lower;
typedef CGAL::Null_functor Upper;
typedef CGAL::Null_functor Width;
typedef CGAL::Null_functor Median;
typedef CGAL::Null_functor Norm;
typedef CGAL::Null_functor Empty;
typedef CGAL::Null_functor Singleton;
typedef CGAL::Null_functor In;
typedef CGAL::Null_functor Zero_in;
typedef CGAL::Null_functor Equal;
typedef CGAL::Null_functor Overlap;
typedef CGAL::Null_functor Subset;
typedef CGAL::Null_functor Proper_Subset;
typedef CGAL::Null_functor Intersection;
typedef CGAL::Null_functor Hull;
};
}
template<typename T> struct Interval_traits;
class Exception_intersection_is_empty{};
// function returning type Boundary
template<typename Interval> inline
typename Interval_traits<Interval>::Boundary
lower(const Interval& interval) {
typename Interval_traits<Interval>::Lower lower;
return lower(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Boundary
upper(const Interval& interval) {
typename Interval_traits<Interval>::Upper upper;
return upper(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Boundary
width(Interval interval) {
typename Interval_traits<Interval>::Width width;
return width(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Boundary
median(Interval interval) {
typename Interval_traits<Interval>::Median median;
return median(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Boundary
norm(Interval interval) {
typename Interval_traits<Interval>::Norm norm;
return norm(interval);
}
// functions returning bool
template<typename Interval> inline
typename Interval_traits<Interval>::Empty::result_type
empty(Interval interval) {
typename Interval_traits<Interval>::Empty empty;
return empty(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Singleton::result_type
singleton(Interval interval) {
typename Interval_traits<Interval>::Singleton singleton;
return singleton(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::In::result_type
in(typename Interval_traits<Interval>::Boundary x, Interval interval) {
typename Interval_traits<Interval>::In in;
return in(x,interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Zero_in::result_type
zero_in(Interval interval) {
typename Interval_traits<Interval>::Zero_in zero_in;
return zero_in(interval);
}
// This ones should be removed, since even boost_1_35_0 has changed to zero_in
template<typename Interval> inline
typename Interval_traits<Interval>::Zero_in::result_type
in_zero(Interval interval) {
typename Interval_traits<Interval>::Zero_in zero_in;
return zero_in(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Equal::result_type
equal(Interval interval1,Interval interval2) {
typename Interval_traits<Interval>::Equal equal;
return equal(interval1,interval2);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Overlap::result_type
overlap(Interval interval1, Interval interval2) {
typename Interval_traits<Interval>::Overlap overlap;
return overlap(interval1, interval2);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Subset::result_type
subset(Interval interval1, Interval interval2) {
typename Interval_traits<Interval>::Subset subset;
return subset(interval1, interval2);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Proper_subset::result_type
proper_subset(Interval interval1, Interval interval2) {
typename Interval_traits<Interval>::Proper_subset proper_subset;
return proper_subset(interval1, interval2);
}
// Set operations, functions returing Interval
template<typename Interval> inline
typename Interval_traits<Interval>::Intersection::result_type
intersection(Interval interval1, Interval interval2) {
typename Interval_traits<Interval>::Intersection intersection;
return intersection(interval1, interval2);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Hull::result_type
hull(Interval interval1, Interval interval2) {
typename Interval_traits<Interval>::Hull hull;
return hull(interval1, interval2);
}
CGAL_END_NAMESPACE
#endif // CGAL_INTERVAL_TRAITS_H

View File

@ -30,11 +30,14 @@
CGAL_BEGIN_NAMESPACE
template<>
class Interval_traits<CORE::BigFloat> {
class Interval_traits<CORE::BigFloat>
: public CGALi::Interval_traits_base<CORE::BigFloat>{
public:
typedef Interval_traits<CORE::BigFloat> Self;
typedef CORE::BigFloat Interval;
typedef CORE::BigFloat Boundary;
typedef Interval_traits<CORE::BigFloat> Self;
typedef CGAL::Tag_true Is_interval;
struct Lower :public Unary_function<Interval,Boundary>{
Boundary operator() ( Interval x ) const {
@ -176,12 +179,7 @@ public:
}
};
struct Singleton {
// type for the \c AdaptableUnaryFunction concept.
typedef Interval argument_type;
// type for the \c AdaptableUnaryFunction concept.
typedef bool result_type;
struct Singleton :public Unary_function<Interval,bool> {
bool operator() ( Interval x ) const {
return (x.err() == 0);
}
@ -203,27 +201,36 @@ template<typename BFI> long get_significant_bits(BFI bfi);
CORE::BigFloat
inline
round(const CORE::BigFloat& x, long rel_prec = CORE::defRelPrec.toLong() ){CGAL_postcondition(rel_prec >= 0);
// since there is not rel prec defined if Zero_in(x)
if (x.isZeroIn()) return x;
if (CGAL::get_significant_bits(x) <= rel_prec) return x;
// if 1
BigFloat xr;
xr.approx(x,rel_prec,1024);
typedef CORE::BigFloat BF;
typedef CORE::BigFloat BFI;
typedef CORE::BigInt Integer;
BF xr;
// else
// typedef CORE::BigFloat BF;
// typedef CORE::BigFloat BFI;
// typedef CORE::BigInt Integer;
// BF xr;
CORE::BigInt m = x.m();
long err = x.err();
long exp = x.exp();
// CORE::BigInt m = x.m();
// long err = x.err();
// long exp = x.exp();
long shift = ::CORE::bitLength(m) - rel_prec - 1;
if( shift > 0 ){ Integer new_m = m >> shift ;
if(err == 0){ xr = BF(new_m,1,0)*BF::exp2(exp*14+shift);
}else{ xr = BF(new_m,2,0)*BF::exp2(exp*14+shift);
}
}else{ // noting to do
xr = x;
}
// long shift = ::CORE::bitLength(m) - rel_prec - 1;
// if( shift > 0 ){ Integer new_m = m >> shift ;
// if(err == 0){ xr = BF(new_m,1,0)*BF::exp2(exp*14+shift);
// }else{ xr = BF(new_m,2,0)*BF::exp2(exp*14+shift);
// }
// }else{ // noting to do
// xr = x;
// }
// endif
CGAL_postcondition(CGAL::abs(CGAL::get_significant_bits(xr) - rel_prec) <= 1);
CGAL_postcondition(BF(xr.m()-xr.err(),0,xr.exp()) <= BF(x.m()-x.err(),0,x.exp()));
@ -232,6 +239,7 @@ round(const CORE::BigFloat& x, long rel_prec = CORE::defRelPrec.toLong() ){CGAL_
}
template<> class Bigfloat_interval_traits<CORE::BigFloat>
:public Interval_traits<CORE::BigFloat>
{
public:
typedef CORE::BigFloat NT;
@ -280,8 +288,6 @@ public:
};
struct Convert_to_bfi {
typedef NT result_type;
NT operator() (const ::CORE::Expr& x){

View File

@ -43,135 +43,11 @@
#define CGAL_INTERVAL_SUPPORT_H
#include <CGAL/basic.h>
#include <CGAL/Interval_traits.h>
CGAL_BEGIN_NAMESPACE
template<typename Interval> class Interval_traits;
class Exception_intersection_is_empty{};
// function returning type Boundary
template<typename Interval> inline
typename Interval_traits<Interval>::Boundary
lower(const Interval& interval) {
typename Interval_traits<Interval>::Lower lower;
return lower(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Boundary
upper(const Interval& interval) {
typename Interval_traits<Interval>::Upper upper;
return upper(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Boundary
width(Interval interval) {
typename Interval_traits<Interval>::Width width;
return width(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Boundary
median(Interval interval) {
typename Interval_traits<Interval>::Median median;
return median(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Boundary
norm(Interval interval) {
typename Interval_traits<Interval>::Norm norm;
return norm(interval);
}
// functions returning bool
template<typename Interval> inline
typename Interval_traits<Interval>::Empty::result_type
empty(Interval interval) {
typename Interval_traits<Interval>::Empty empty;
return empty(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Singleton::result_type
singleton(Interval interval) {
typename Interval_traits<Interval>::Singleton singleton;
return singleton(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::In::result_type
in(typename Interval_traits<Interval>::Boundary x, Interval interval) {
typename Interval_traits<Interval>::In in;
return in(x,interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Zero_in::result_type
zero_in(Interval interval) {
typename Interval_traits<Interval>::Zero_in zero_in;
return zero_in(interval);
}
// This ones should be removed, since even boost_1_35_0 has changed to zero_in
template<typename Interval> inline
typename Interval_traits<Interval>::Zero_in::result_type
in_zero(Interval interval) {
typename Interval_traits<Interval>::Zero_in zero_in;
return zero_in(interval);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Equal::result_type
equal(Interval interval1,Interval interval2) {
typename Interval_traits<Interval>::Equal equal;
return equal(interval1,interval2);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Overlap::result_type
overlap(Interval interval1, Interval interval2) {
typename Interval_traits<Interval>::Overlap overlap;
return overlap(interval1, interval2);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Subset::result_type
subset(Interval interval1, Interval interval2) {
typename Interval_traits<Interval>::Subset subset;
return subset(interval1, interval2);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Proper_subset::result_type
proper_subset(Interval interval1, Interval interval2) {
typename Interval_traits<Interval>::Proper_Subset proper_subset;
return proper_subset(interval1, interval2);
}
// Set operations, functions returing Interval
template<typename Interval> inline
typename Interval_traits<Interval>::Intersection::result_type
intersection(Interval interval1, Interval interval2) {
typename Interval_traits<Interval>::Intersection intersection;
return intersection(interval1, interval2);
}
template<typename Interval> inline
typename Interval_traits<Interval>::Hull::result_type
hull(Interval interval1, Interval interval2) {
typename Interval_traits<Interval>::Hull hull;
return hull(interval1, interval2);
}
// This will go intro bigfloat_interval_support.h
// This will go into bigfloat_interval_support.h
//////////////////////////////// BFI Traits
@ -184,12 +60,12 @@ template<typename BFI> inline long get_significant_bits(BFI bfi) {
return get_significant_bits(bfi);
}
template<typename BFI> inline long set_precision(BFI bfi,long prec) {
template<typename BFI> inline long set_precision(BFI,long prec) {
typename Bigfloat_interval_traits<BFI>::Set_precision set_precision;
return set_precision(prec);
}
template<typename BFI> inline long get_precision(BFI bfi) {
template<typename BFI> inline long get_precision(BFI) {
typename Bigfloat_interval_traits<BFI>::Get_precision get_precision;
return get_precision();
}
@ -200,10 +76,15 @@ template <class NTX> struct Get_arithmetic_kernel;
template <class NTX>
typename Get_arithmetic_kernel<NTX>::Arithmetic_kernel::Bigfloat_interval
convert_to_bfi(const NTX& x) {
typedef typename Get_arithmetic_kernel<NTX>::Arithmetic_kernel AT;
typedef typename AT::Bigfloat_interval BFI;
typename Bigfloat_interval_traits<BFI>::Convert_to_bfi convert_to_bfi;
return convert_to_bfi(x);
typedef typename Get_arithmetic_kernel<NTX>::Arithmetic_kernel AK;
typedef typename AK::Bigfloat_interval BFI;
typedef CGAL::Coercion_traits<NTX,BFI> CT;
return typename CT::Cast()(x);
// typedef typename Get_arithmetic_kernel<NTX>::Arithmetic_kernel AT;
// typedef typename AT::Bigfloat_interval BFI;
// typename Bigfloat_interval_traits<BFI>::Convert_to_bfi convert_to_bfi;
// return convert_to_bfi(x);
}
// TODO: move this to sqrt_extension ?

View File

@ -101,6 +101,9 @@ template <> class Real_embeddable_traits< leda_bigfloat >
const Type& y ) const {
return (Comparison_result) CGAL_LEDA_SCOPE::compare( x, y );
}
CGAL_IMPLICIT_INTEROPERABLE_BINARY_OPERATOR_WITH_RT( Type,
Comparison_result );
};
class To_double

View File

@ -17,6 +17,10 @@
#include <LEDA/numbers/bigfloat.h>
#endif
#include <CGAL/leda_integer.h>
#include <CGAL/leda_rational.h>
#include <CGAL/leda_real.h>
#include <CGAL/leda_bigfloat.h>
#include <boost/numeric/interval.hpp>
CGAL_BEGIN_NAMESPACE
@ -192,6 +196,90 @@ public:
};
// Coercion traits:
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,leda_bigfloat_interval);
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,leda_bigfloat_interval);
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,leda_bigfloat_interval);
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,leda_bigfloat_interval);
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,leda_bigfloat_interval);
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::leda::bigfloat ,leda_bigfloat_interval);
template <>
struct Coercion_traits< leda_bigfloat_interval , ::leda::integer >{
typedef Tag_true Are_explicit_interoperable;
typedef Tag_false Are_implicit_interoperable;
typedef leda_bigfloat_interval Type;
struct Cast{
typedef Type result_type;
Type operator()(const leda_bigfloat_interval& x) const { return x;}
Type operator()(const ::leda::integer x) const {
leda::bigfloat tmp(x);
leda_bigfloat_interval result(
round(tmp,leda::bigfloat::get_precision(),leda::TO_N_INF),
round(tmp,leda::bigfloat::get_precision(),leda::TO_P_INF));
CGAL_postcondition( result.lower() <= x );
CGAL_postcondition( result.upper() >= x );
return result;
}
};
};
template <>
struct Coercion_traits< leda_bigfloat_interval , ::leda::rational >{
typedef Tag_true Are_explicit_interoperable;
typedef Tag_false Are_implicit_interoperable;
typedef leda_bigfloat_interval Type;
struct Cast{
typedef Type result_type;
Type operator()(const leda_bigfloat_interval& x) const { return x;}
Type operator()(const ::leda::rational x) const {
leda_bigfloat_interval result (
leda_bigfloat::from_rational(x, ::leda::bigfloat::get_precision(), leda::TO_N_INF),
leda_bigfloat::from_rational(x, ::leda::bigfloat::get_precision(), leda::TO_P_INF));
CGAL_postcondition( result.lower() <= x );
CGAL_postcondition( result.upper() >= x );
return result;
}
};
};
template <>
struct Coercion_traits< leda_bigfloat_interval , ::leda::real >{
typedef Tag_true Are_explicit_interoperable;
typedef Tag_false Are_implicit_interoperable;
typedef leda_bigfloat_interval Type;
struct Cast{
typedef Type result_type;
Type operator()(const leda_bigfloat_interval& x) const { return x;}
Type operator()(const ::leda::real x) const {
long current_prec = ::leda::bigfloat::get_precision();
x.guarantee_relative_error(current_prec);
leda_bigfloat_interval result(x.get_lower_bound(), x.get_upper_bound());
CGAL_postcondition( result.lower() <= x );
CGAL_postcondition( result.upper() >= x );
return result;
}
};
};
template <> struct Coercion_traits< ::leda::integer, leda_bigfloat_interval >
:public Coercion_traits< leda_bigfloat_interval , ::leda::integer >{};
template <> struct Coercion_traits< ::leda::rational, leda_bigfloat_interval >
:public Coercion_traits< leda_bigfloat_interval , ::leda::rational >{};
template <> struct Coercion_traits< ::leda::real, leda_bigfloat_interval >
:public Coercion_traits< leda_bigfloat_interval , ::leda::real>{};
CGAL_END_NAMESPACE
#endif // CGAL_USE_LEDA
#endif // CGAL_LEDA_BIGFLOAT_INTERVAL_H

View File

@ -43,7 +43,6 @@
#include <LEDA/numbers/real.h>
#endif
CGAL_BEGIN_NAMESPACE
@ -87,6 +86,7 @@ CGAL_BEGIN_NAMESPACE
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::leda::real)
CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::leda::real)
//not provided by LEDA
//Note that this is not symmetric to CORE
//CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long long,::leda::integer);

View File

@ -34,7 +34,8 @@ public:
typedef Interval_traits<leda_bigfloat_interval> Self;
typedef leda_bigfloat_interval Interval;
typedef leda::bigfloat Boundary;
typedef CGAL::Tag_true Is_interval;
typedef CGAL::Tag_true With_empty_interval;
struct Construct :public Binary_function<Boundary,Boundary,Interval>{
Interval operator()( const Boundary& l,const Boundary& r) const {
@ -129,9 +130,7 @@ public:
struct Intersection :public Binary_function<Interval,Interval,Interval>{
Interval operator()( const Interval& a, const Interval& b ) const {
Interval r = ::boost::numeric::intersect(a,b);
if (::boost::numeric::empty(r))
throw Exception_intersection_is_empty();
Interval r = ::boost::numeric::intersect(a,b);
return r;
}
};
@ -186,78 +185,79 @@ public:
}
};
struct Convert_to_bfi {
/*
struct Convert_to_bfi {
typedef NT result_type;
typedef NT result_type;
NT operator()( const leda::real& x ) {
long current_prec = ::leda::bigfloat::get_precision();
//x.improve_approximation_to(current_prec);
x.guarantee_relative_error(current_prec);
NT operator()( const leda::real& x ) {
long current_prec = ::leda::bigfloat::get_precision();
//x.improve_approximation_to(current_prec);
x.guarantee_relative_error(current_prec);
leda::bigfloat bnum = x.to_bigfloat();
leda::bigfloat berr = x.get_bigfloat_error();
leda::bigfloat bnum = x.to_bigfloat();
leda::bigfloat berr = x.get_bigfloat_error();
leda::bigfloat low
= leda::sub(bnum,berr,current_prec,LEDA::TO_N_INF);
leda::bigfloat upp
= leda::add(bnum,berr,current_prec,LEDA::TO_P_INF);
leda_bigfloat_interval bfi(low,upp) ;
leda::bigfloat low
= leda::sub(bnum,berr,current_prec,LEDA::TO_N_INF);
leda::bigfloat upp
= leda::add(bnum,berr,current_prec,LEDA::TO_P_INF);
leda_bigfloat_interval bfi(low,upp) ;
// std::cout <<"x: "<< x << std::endl;
// std::cout <<"bfi.lower(): "<< bfi.lower() << std::endl;
// std::cout <<"bfi.upper(): "<< bfi.upper() << std::endl;
// std::cout <<"x: "<< x << std::endl;
// std::cout <<"bfi.lower(): "<< bfi.lower() << std::endl;
// std::cout <<"bfi.upper(): "<< bfi.upper() << std::endl;
CGAL_postcondition( bfi.lower() <= x );
CGAL_postcondition( bfi.upper() >= x );
CGAL_postcondition( bfi.lower() <= x );
CGAL_postcondition( bfi.upper() >= x );
return bfi;
}
return bfi;
}
NT operator()(const ::leda::integer& x) {
long current_prec = ::leda::bigfloat::get_precision();
leda_bigfloat_interval bfi;
long length = x.length();
NT operator()(const ::leda::integer& x) {
long current_prec = ::leda::bigfloat::get_precision();
leda_bigfloat_interval bfi;
long length = x.length();
if(length > current_prec) {
::leda::integer significant
= CGAL::abs(x) >> (length - current_prec);
::leda::bigfloat lower,upper;
if(x > 0){
lower = ::leda::bigfloat(significant,length - current_prec);
upper = ::leda::bigfloat(significant+1,length - current_prec);
}else{
lower
= -::leda::bigfloat(significant+1,length - current_prec);
upper
= -::leda::bigfloat(significant,length - current_prec);
}
bfi = leda_bigfloat_interval(lower,upper);
}else{
::leda::bigfloat bf(x);
bfi = leda_bigfloat_interval(bf,bf);
}
CGAL_postcondition( bfi.lower() <= x );
CGAL_postcondition( bfi.upper() >= x );
return bfi;
}
if(length > current_prec) {
::leda::integer significant
= CGAL::abs(x) >> (length - current_prec);
::leda::bigfloat lower,upper;
if(x > 0){
lower = ::leda::bigfloat(significant,length - current_prec);
upper = ::leda::bigfloat(significant+1,length - current_prec);
}else{
lower
= -::leda::bigfloat(significant+1,length - current_prec);
upper
= -::leda::bigfloat(significant,length - current_prec);
}
bfi = leda_bigfloat_interval(lower,upper);
}else{
::leda::bigfloat bf(x);
bfi = leda_bigfloat_interval(bf,bf);
}
CGAL_postcondition( bfi.lower() <= x );
CGAL_postcondition( bfi.upper() >= x );
return bfi;
}
NT operator()(const ::leda::rational& x) {
long old_prec = ::leda::bigfloat::get_precision();
::leda::bigfloat::set_precision(old_prec*2);
Bigfloat_interval_traits<NT>::Convert_to_bfi convert_to_bfi;
leda_bigfloat_interval num = convert_to_bfi(x.numerator());
leda_bigfloat_interval den = convert_to_bfi(x.denominator());
::leda::bigfloat::set_precision(old_prec);
leda_bigfloat_interval bfi = num/den;
CGAL_postcondition( bfi.lower() <= x );
CGAL_postcondition( bfi.upper() >= x );
return bfi;
}
};
NT operator()(const ::leda::rational& x) {
long old_prec = ::leda::bigfloat::get_precision();
::leda::bigfloat::set_precision(old_prec*2);
Bigfloat_interval_traits<NT>::Convert_to_bfi convert_to_bfi;
leda_bigfloat_interval num = convert_to_bfi(x.numerator());
leda_bigfloat_interval den = convert_to_bfi(x.denominator());
::leda::bigfloat::set_precision(old_prec);
leda_bigfloat_interval bfi = num/den;
CGAL_postcondition( bfi.lower() <= x );
CGAL_postcondition( bfi.upper() >= x );
return bfi;
}
};
*/
};

View File

@ -6,6 +6,7 @@
#include <CGAL/CORE_BigFloat.h>
#include <CGAL/Test/_test_algebraic_structure.h>
#include <CGAL/Test/_test_real_embeddable.h>
#include <CGAL/Test/_test_interval.h>
int main() {
typedef CORE::BigFloat NT;
@ -22,7 +23,7 @@ int main() {
CGAL::test_algebraic_structure<NT,Tag, Is_exact>(NT(-4),NT(-6),NT(-15));
CGAL::test_real_embeddable<NT>();
CGAL::test_interval<NT>();
return 0;
}

View File

@ -32,66 +32,91 @@
typedef CGAL::Interval_nt<false> Interval;
template <class AT>
void AT_coercion_test_at_int(){
typedef typename AT::Integer Integer;
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<short ,Integer>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<int ,Integer>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<Integer,Integer>();
}
void test_coercion_from_to(CGAL::Null_tag, CGAL::Null_tag){};
template<class A> void test_coercion_from_to(A, CGAL::Null_tag){};
template<class B> void test_coercion_from_to(CGAL::Null_tag, B){};
template<class A, class B> void test_coercion_from_to(A, B){
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<A,B>();
};
template <class AT>
void AT_coercion_test_at_bf(){
AT_coercion_test_at_int<AT>();
typedef typename AT::Integer Integer;
typedef typename AT::Exact_float_number Bigfloat;
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<short ,Bigfloat>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<int ,Bigfloat>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<float ,Bigfloat>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<double ,Bigfloat>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<Integer ,Bigfloat>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<Bigfloat,Bigfloat>();
}
template <class AT>
void AT_coercion_test_at_rat(){
AT_coercion_test_at_bf<AT>();;
typedef typename AT::Integer Integer;
typedef typename AT::Exact_float_number Bigfloat;
typedef typename AT::Rational Rational;
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<short ,Rational>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<int ,Rational>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<float ,Rational>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<double ,Rational>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<Integer ,Rational>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<Bigfloat ,Rational>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<Rational,Rational>();
}
template <class AT>
void AT_coercion_test_at_fws(){
AT_coercion_test_at_rat<AT>();
void check_type_coercion_at(){
typedef typename AT::Integer Integer;
typedef typename AT::Rational Rational;
typedef typename AT::Field_with_sqrt Field_with_sqrt;
typedef typename AT::Field_with_kth_root Field_with_kth_root;
typedef typename AT::Field_with_root_of Field_with_root_of;
typedef typename AT::Bigfloat Bigfloat;
typedef typename AT::Bigfloat_interval Bigfloat_interval;
typedef typename AT::Integer Integer;
typedef typename AT::Exact_float_number Bigfloat;
typedef typename AT::Rational Rational;
typedef typename AT::Field_with_sqrt Real;
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<short ,Real>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<int ,Real>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<float ,Real>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<double ,Real>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<Integer ,Real>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<Bigfloat ,Real>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<Rational ,Real>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<Real ,Real>();
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());
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 <class AT>
void AT_coercion_test_for_cgal_types_int(){
typedef typename AT::Integer Integer;
@ -376,7 +401,6 @@ int main(){
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<int,float>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<int,double>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<int,long double>();
CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test<long,long long>();
@ -415,15 +439,18 @@ int main(){
#endif // CGAL_HAVE_DEFAULT_ARITHMETIC_KERNEL
#ifdef CGAL_USE_LEDA
AT_coercion_test_at_fws<CGAL::LEDA_arithmetic_kernel>();
check_type_coercion_at<CGAL::LEDA_arithmetic_kernel>();
AT_coercion_test_for_cgal_types_fws<CGAL::LEDA_arithmetic_kernel>();
#endif // CGAL_USE_LEDA
#ifdef CGAL_USE_CORE
AT_coercion_test_at_fws<CGAL::CORE_arithmetic_kernel>();
check_type_coercion_at<CGAL::CORE_arithmetic_kernel>();
AT_coercion_test_for_cgal_types_fws<CGAL::CORE_arithmetic_kernel>();
#endif // CGAL_USE_CORE
#ifdef CGAL_USE_GMP
AT_coercion_test_at_rat<CGAL::GMP_arithmetic_kernel>();
check_type_coercion_at<CGAL::GMP_arithmetic_kernel>();
AT_coercion_test_for_cgal_types_rat<CGAL::CORE_arithmetic_kernel>();
#endif // CGAL_USE_GMP
return EXIT_SUCCESS;

View File

@ -0,0 +1,221 @@
// TODO: Add licence
//
// 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 <hemmer@mpi-inf.mpg.de>
//
// ============================================================================
//
// \brief provides test functions for the \c Interval concept.
// TODO: Add Is_empty?
#include <CGAL/basic.h>
#include <CGAL/Test/_test_basic.h>
#include <cstddef>
#include <boost/static_assert.hpp>
#include <boost/type_traits.hpp>
#include <cassert>
#include <CGAL/tags.h>
#include <CGAL/interval_support.h>
#ifndef CGAL_TEST_INTERVAL_H
#define CGAL_TEST_INTERVAL_H
CGAL_BEGIN_NAMESPACE
template <class Interval>
void test_with_empty_interval(CGAL::Tag_false) {
typedef CGAL::Interval_traits<Interval> IT;
typedef typename IT::Empty Empty;
BOOST_STATIC_ASSERT(
(::boost::is_same< Empty, CGAL::Null_functor>::value));
// this part chages in case we allow empty intersection
// which seems to be not possible for CORE::BigFloat as Interval
try{
try{
typename IT::Intersection()(Interval(1),Interval(2));
assert(false); // it should not reach this
}
catch(CGAL::Exception_intersection_is_empty){} // it throws the right exception
}catch(...){
assert(false); // seems to be the wrong exception
}
}
template <class Interval>
void test_with_empty_interval(CGAL::Tag_true) {
typedef CGAL::Interval_traits<Interval> IT;
typedef typename IT::Empty Empty;
Test_functor_arity<Empty >()(1);
const Empty empty = Empty();
assert(empty(typename IT::Intersection()(Interval(1),Interval(2))));
}
template <class Interval>
void test_interval() {
typedef CGAL::Interval_traits<Interval> IT;
typedef typename IT::Boundary Boundary;
typedef typename IT::Is_interval Is_interval;
typedef typename IT::With_empty_interval With_empty_interval;
using CGAL::Tag_true;
BOOST_STATIC_ASSERT(( ::boost::is_same< Is_interval, Tag_true>::value));
test_with_empty_interval<Interval>(With_empty_interval());
typedef typename IT::Construct Construct;
typedef typename IT::Lower Lower;
typedef typename IT::Upper Upper;
typedef typename IT::Width Width;
typedef typename IT::Median Median;
typedef typename IT::Norm Norm;
typedef typename IT::Singleton Singleton;
typedef typename IT::In In;
typedef typename IT::Zero_in Zero_in;
typedef typename IT::Equal Equal;
typedef typename IT::Overlap Overlap;
typedef typename IT::Subset Subset;
typedef typename IT::Proper_subset Proper_subset;
typedef typename IT::Intersection Intersection;
typedef typename IT::Hull Hull;
Test_functor_arity<Construct >()(2);
Test_functor_arity<Lower >()(1);
Test_functor_arity<Upper >()(1);
Test_functor_arity<Width >()(1);
Test_functor_arity<Median >()(1);
Test_functor_arity<Norm >()(1);
Test_functor_arity<Singleton >()(1);
Test_functor_arity<In >()(2);
Test_functor_arity<Zero_in >()(1);
Test_functor_arity<Equal >()(2);
Test_functor_arity<Overlap >()(2);
Test_functor_arity<Subset >()(2);
Test_functor_arity<Proper_subset >()(2);
Test_functor_arity<Intersection >()(2);
Test_functor_arity<Hull >()(2);
const Construct construct = Construct();
const Lower lower = Lower();
const Upper upper = Upper();
const Width width = Width();
const Median median = Median();
const Norm norm = Norm();
const Singleton singleton = Singleton();
const In in = In();
const Zero_in zero_in = Zero_in();
const Equal equal = Equal();
const Overlap overlap = Overlap();
const Subset subset = Subset();
const Proper_subset proper_subset = Proper_subset();
const Intersection intersection = Intersection();
const Hull hull = Hull();
Interval a(construct(Boundary(-7),Boundary(-5)));
Interval b(construct(Boundary(0),Boundary(4)));
Interval c(construct(Boundary(2),Boundary(6)));
assert(lower(a) == Boundary(-7));
assert(upper(a) == Boundary(-5));
assert(lower(b) == Boundary( 0));
assert(upper(b) == Boundary( 4));
assert(lower(c) == Boundary( 2));
assert(upper(c) == Boundary( 6));
assert(width(a) == Boundary( 2));
assert(median(a) == Boundary(-6));
assert(norm(a) == Boundary( 7));
// assert(!empty(a));
assert( singleton(Interval(1)));
assert(!singleton(a));
assert(!singleton(b));
assert(!singleton(c));
assert(!zero_in(Interval(1)));
assert( zero_in(Interval(0)));
assert(!zero_in(a));
assert( zero_in(b));
assert(!zero_in(c));
//########
// to be remove again
assert(!CGAL::in_zero(Interval(1)));
assert( CGAL::in_zero(Interval(0)));
assert(!CGAL::in_zero(a));
assert( CGAL::in_zero(b));
assert(!CGAL::in_zero(c));
//#########
assert(!in(Boundary( 3),a));
assert( in(Boundary(-7),a));
assert( equal(a,a));
assert( equal(b,b));
assert( equal(c,c));
assert(!equal(a,b));
assert(!equal(a,c));
assert(!overlap(a,b));
assert( overlap(b,c));
Interval I25 = construct(Boundary(2),Boundary(5));
assert(overlap(I25, construct(Boundary(6),Boundary(7))) == false);
assert(overlap(I25, construct(Boundary(5),Boundary(6))) == true);
assert(overlap(I25, construct(Boundary(4),Boundary(5))) == true);
assert(overlap(I25, construct(Boundary(3),Boundary(4))) == true);
assert(overlap(I25, construct(Boundary(2),Boundary(3))) == true);
assert(overlap(I25, construct(Boundary(1),Boundary(2))) == true);
assert(overlap(I25, construct(Boundary(0),Boundary(1))) == false);
assert(!subset(a,b));
assert( subset(a,a));
assert( subset(Interval(-6),a));
assert(!proper_subset(a,b));
assert(!proper_subset(a,a));
assert( proper_subset(Interval(-6),a));
// assert( empty(intersection(a,b)));
assert( lower(intersection(b,c)) == Boundary(2));
assert( upper(intersection(b,c)) == Boundary(4));
// hull
assert(lower(hull(b,c)) == Boundary(0));
assert(upper(hull(b,c)) == Boundary(6));
assert(lower(hull(Interval(2),Interval(5))) >= Boundary(1));
assert(lower(hull(Interval(2),Interval(5))) <= Boundary(2));
assert(upper(hull(Interval(2),Interval(5))) >= Boundary(5));
assert(upper(hull(Interval(2),Interval(5))) <= Boundary(6));
// singleton
assert(singleton(hull(Interval(2),Interval(2))) == true);
assert(singleton(hull(Interval(2),Interval(3))) == false);
// width
assert(width(hull(Interval(2),Interval(2))) == Boundary(0));
assert(width(hull(Interval(2),Interval(3))) == Boundary(1));
}
CGAL_END_NAMESPACE
#endif // CGAL_TEST_REAL_COMPARABLE_H

View File

@ -10,6 +10,8 @@
#include <CGAL/leda_interval_support.h>
#endif
#include <CGAL/Test/_test_interval.h>
template<class Interval_>
void generic_test_interval(){
@ -176,14 +178,12 @@ void generic_test_convert_to_bfi(){
int main(){
#ifdef CGAL_USE_LEDA
generic_test_interval<CGAL::leda_bigfloat_interval>();
CGAL::test_interval<CGAL::leda_bigfloat_interval>();
generic_test_bigfloat_interval<CGAL::leda_bigfloat_interval>();
#endif
#ifdef CGAL_USE_CORE
generic_test_interval<CORE::BigFloat>();
CGAL::test_interval<CORE::BigFloat>();
generic_test_bigfloat_interval<CORE::BigFloat>();
#endif

View File

@ -0,0 +1,31 @@
#include <iostream>
#include <CGAL/basic.h>
#ifdef CGAL_USE_LEDA
#include <CGAL/leda_bigfloat_interval.h>
#include <CGAL/Test/_test_algebraic_structure.h>
#include <CGAL/Test/_test_real_embeddable.h>
#include <CGAL/Test/_test_interval.h>
int main() {
typedef CGAL::leda_bigfloat_interval NT;
typedef CGAL::Field_with_sqrt_tag Tag;
typedef CGAL::Tag_false Is_exact;
CGAL::test_algebraic_structure<NT,Tag, Is_exact>();
CGAL::test_algebraic_structure<NT,Tag, Is_exact>(NT(4),NT(6),NT(15));
CGAL::test_algebraic_structure<NT,Tag, Is_exact>(NT(-4),NT(6),NT(15));
CGAL::test_algebraic_structure<NT,Tag, Is_exact>(NT(4),NT(-6),NT(15));
CGAL::test_algebraic_structure<NT,Tag, Is_exact>(NT(-4),NT(-6),NT(15));
CGAL::test_algebraic_structure<NT,Tag, Is_exact>(NT(4),NT(6),NT(-15));
CGAL::test_algebraic_structure<NT,Tag, Is_exact>(NT(-4),NT(6), NT(15));
CGAL::test_algebraic_structure<NT,Tag, Is_exact>(NT(4),NT(-6),NT(-15));
CGAL::test_algebraic_structure<NT,Tag, Is_exact>(NT(-4),NT(-6),NT(-15));
CGAL::test_real_embeddable<NT>();
CGAL::test_interval<NT>();
return 0;
}
#else
int main() { return 0; }
#endif