mirror of https://github.com/CGAL/cgal
rm interval_support
added Interval_traits, Bigfloat_interval_traits mv function convert_to_bfi into extra file convert_to_bfi.h
This commit is contained in:
parent
8320234d00
commit
4603598e7c
|
|
@ -2886,9 +2886,6 @@ Number_types/include/CGAL/Sqrt_extension/Real_embeddable_traits.h -text
|
|||
Number_types/include/CGAL/Sqrt_extension/Scalar_factor_traits.h -text
|
||||
Number_types/include/CGAL/Sqrt_extension/Sqrt_extension_type.h -text
|
||||
Number_types/include/CGAL/Sqrt_extension/io.h -text
|
||||
Number_types/include/CGAL/core_interval_support.h -text
|
||||
Number_types/include/CGAL/interval_support.h -text
|
||||
Number_types/include/CGAL/leda_interval_support.h -text
|
||||
Optimisation_doc/doc_tex/Bounding_volumes/annulus.eps -text svneol=unset#application/postscript
|
||||
Optimisation_doc/doc_tex/Bounding_volumes/annulus.gif -text svneol=unset#image/gif
|
||||
Optimisation_doc/doc_tex/Bounding_volumes/annulus.pdf -text svneol=unset#application/pdf
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@
|
|||
#include <CGAL/leda_rational.h>
|
||||
#include <CGAL/leda_bigfloat.h>
|
||||
#include <CGAL/leda_real.h>
|
||||
|
||||
#include <CGAL/leda_interval_support.h>
|
||||
#include <CGAL/leda_bigfloat_interval.h>
|
||||
|
||||
#endif // CGAL_USE_LEDA
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright (c) 2006-2007 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 <hemmer@mpi-inf.mpg.de>
|
||||
// Ron Wein <wein@post.tau.ac.il>
|
||||
|
||||
|
||||
#ifndef CGAL_BIGFLOAT_INTERVAL_TRAITS_H
|
||||
#define CGAL_BIGFLOAT_INTERVAL_TRAITS_H
|
||||
|
||||
#include<CGAL/basic.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
// TODO: rename this into MPFI_traits ?
|
||||
// add a better rounding control
|
||||
|
||||
template<typename BigfloatInterval> class Bigfloat_interval_traits;
|
||||
|
||||
template<typename BFI> inline long get_significant_bits(BFI bfi) {
|
||||
typename Bigfloat_interval_traits<BFI>::Get_significant_bits
|
||||
get_significant_bits;
|
||||
return get_significant_bits(bfi);
|
||||
}
|
||||
|
||||
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) {
|
||||
typename Bigfloat_interval_traits<BFI>::Get_precision get_precision;
|
||||
return get_precision();
|
||||
}
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
#endif // CGAL_BIGFLOAT_INTERVAL_TRAITS_H
|
||||
|
|
@ -24,10 +24,276 @@
|
|||
|
||||
#include <CGAL/number_type_basic.h>
|
||||
#include <CGAL/CORE_coercion_traits.h>
|
||||
#include <CGAL/core_interval_support.h>
|
||||
#include <CGAL/Interval_traits.h>
|
||||
#include <CGAL/Bigfloat_interval_traits.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
//template<typename BFI> long inline get_significant_bits(BFI);
|
||||
//CORE::BigFloat inline round(const CORE::BigFloat&, long);
|
||||
|
||||
// ######### Interval_traits
|
||||
|
||||
template<>
|
||||
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 CGAL::Tag_true Is_interval;
|
||||
|
||||
struct Lower :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator() ( Interval x ) const {
|
||||
CORE::BigFloat result = ::CORE::BigFloat(x.m()-x.err(),0,x.exp());
|
||||
CGAL_postcondition(result <= x);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct Upper :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator() ( Interval x ) const {
|
||||
CORE::BigFloat result = ::CORE::BigFloat(x.m()+x.err(),0,x.exp());
|
||||
CGAL_postcondition(result >= x);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct Width :public Unary_function<Interval,Boundary>{
|
||||
|
||||
Boundary operator() ( Interval x ) const {
|
||||
unsigned long err = 2*x.err();
|
||||
return Boundary(CORE::BigInt(err),0,x.exp());
|
||||
}
|
||||
};
|
||||
|
||||
struct Median :public Unary_function<Interval,Boundary>{
|
||||
|
||||
Boundary operator() ( Interval x ) const {
|
||||
return Boundary(x.m(),0,x.exp());
|
||||
}
|
||||
};
|
||||
|
||||
struct Norm :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator() ( Interval x ) const {
|
||||
return std::max(Upper()(x).abs(),Lower()(x).abs());
|
||||
}
|
||||
};
|
||||
|
||||
struct Zero_in :public Unary_function<Interval,bool>{
|
||||
bool operator() ( Interval x ) const {
|
||||
return x.isZeroIn();
|
||||
}
|
||||
};
|
||||
|
||||
struct In :public Binary_function<Boundary,Interval,bool>{
|
||||
bool operator()( Boundary x, const Interval& a ) const {
|
||||
CGAL_precondition(CGAL::singleton(x));
|
||||
return (Lower()(a) <= x && x <= Upper()(a));
|
||||
}
|
||||
};
|
||||
|
||||
struct Equal :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return (Upper()(a) == Upper()(b) && Lower()(a) == Lower()(b));
|
||||
}
|
||||
};
|
||||
|
||||
struct Subset :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return Lower()(b) <= Lower()(a) && Upper()(a) <= Upper()(b);
|
||||
}
|
||||
};
|
||||
|
||||
struct Proper_subset :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return Subset()(a,b) && (!Equal()(a,b));
|
||||
}
|
||||
};
|
||||
|
||||
struct Intersection :public Binary_function<Interval,Interval,Interval>{
|
||||
Interval operator()( const Interval& a, const Interval& b ) const {
|
||||
// std::cout <<"a= (" << a.m() << "+-" << a.err() << ")*2^" << a.exp() << std::endl;
|
||||
Boundary l(CGAL::max(Lower()(a),Lower()(b)));
|
||||
Boundary u(CGAL::min(Upper()(a),Upper()(b)));
|
||||
|
||||
if(u < l ) throw Exception_intersection_is_empty();
|
||||
return Construct()(l,u);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct Overlap :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator() ( Interval x, Interval y ) const {
|
||||
Self::Zero_in Zero_in;
|
||||
bool result = Zero_in(x-y);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct Hull :public Binary_function<Interval,Interval,Interval>{
|
||||
Interval operator() ( Interval x, Interval y ) const {
|
||||
#if 0
|
||||
// this is not possible since CORE::centerize has a bug.
|
||||
Interval result = CORE::centerize(x,y);
|
||||
#else
|
||||
|
||||
CORE::BigFloat result;
|
||||
|
||||
// Unfortunately, CORE::centerize(x,y) has bugs.
|
||||
if ((x.m() == y.m()) && (x.err() == y.err()) && (x.exp() == y.exp())) {
|
||||
return x;
|
||||
}
|
||||
|
||||
CORE::BigFloat lower = std::min(CGAL::lower(x), CGAL::lower(y));
|
||||
CORE::BigFloat upper = std::max(CGAL::upper(x), CGAL::upper(y));
|
||||
|
||||
CORE::BigFloat mid = (lower + upper)/2;
|
||||
|
||||
// Now we have to compute the error. The problem is that .err() is just a long
|
||||
CORE::BigFloat err = (upper - lower)/CORE::BigFloat(2);
|
||||
|
||||
//std::cout << "lower " << lower << std::endl;
|
||||
//std::cout << "upper " << upper << std::endl;
|
||||
//std::cout << "mid " << mid << std::endl;
|
||||
//std::cout << "err I " << err << std::endl;
|
||||
|
||||
// shift such that err.m()+err.err() fits into long
|
||||
int digits_long = std::numeric_limits<long>::digits;
|
||||
if(::CORE::bitLength(err.m()) >= digits_long){
|
||||
long shift = ::CORE::bitLength(err.m()) - digits_long + 1 ;
|
||||
//std::cout << "shift " << shift<< std::endl;
|
||||
long new_err = ((err.m()+err.err()) >> shift).longValue()+1;
|
||||
err = CORE::BigFloat(0,new_err,0) * CORE::BigFloat::exp2(err.exp()*14+shift);
|
||||
}else{
|
||||
err = CORE::BigFloat(0,err.m().longValue()+err.err(),err.exp());
|
||||
}
|
||||
|
||||
result = mid + err;
|
||||
|
||||
#endif
|
||||
CGAL_postcondition(
|
||||
CGAL::lower(result)
|
||||
<= std::min(CGAL::lower(x), CGAL::lower(y)));
|
||||
CGAL_postcondition(
|
||||
CGAL::upper(result)
|
||||
>= std::max(CGAL::upper(x), CGAL::upper(y)));
|
||||
|
||||
return result ;
|
||||
}
|
||||
};
|
||||
|
||||
struct Singleton :public Unary_function<Interval,bool> {
|
||||
bool operator() ( Interval x ) const {
|
||||
return (x.err() == 0);
|
||||
}
|
||||
};
|
||||
|
||||
struct Construct :public Binary_function<Boundary,Boundary,Interval>{
|
||||
Interval operator()( const Boundary& l,const Boundary& r) const {
|
||||
CGAL_precondition( l < r );
|
||||
return Hull()(l,r);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// ########### Bigfloat_interval_traits
|
||||
|
||||
|
||||
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;
|
||||
// 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();
|
||||
|
||||
// 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::get_significant_bits(xr) - rel_prec >= 0);
|
||||
CGAL_postcondition(CGAL::get_significant_bits(xr) - rel_prec <= 32);
|
||||
CGAL_postcondition(BF(xr.m()-xr.err(),0,xr.exp()) <= BF(x.m()-x.err(),0,x.exp()));
|
||||
CGAL_postcondition(BF(xr.m()+xr.err(),0,xr.exp()) >= BF(x.m()+x.err(),0,x.exp()));
|
||||
return xr;
|
||||
}
|
||||
|
||||
template<> class Bigfloat_interval_traits<CORE::BigFloat>
|
||||
:public Interval_traits<CORE::BigFloat>
|
||||
{
|
||||
public:
|
||||
typedef CORE::BigFloat NT;
|
||||
typedef CORE::BigFloat BF;
|
||||
|
||||
typedef Bigfloat_interval_traits<NT> Self;
|
||||
|
||||
// How about retuning
|
||||
struct Get_significant_bits {
|
||||
// type for the \c AdaptableUnaryFunction concept.
|
||||
typedef NT argument_type;
|
||||
// type for the \c AdaptableUnaryFunction concept.
|
||||
typedef long result_type;
|
||||
|
||||
long operator()( NT x) const {
|
||||
if(x.err() == 0 ) {
|
||||
return ::CORE::bitLength(x.m());
|
||||
}
|
||||
else {
|
||||
return ::CORE::bitLength(x.m()) - ::CORE::bitLength(x.err());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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 result = ::CORE::defRelPrec.toLong();
|
||||
::CORE::defRelPrec = prec;
|
||||
::CORE::defBFdivRelPrec = prec;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct Get_precision {
|
||||
// type for the \c AdaptableGenerator concept.
|
||||
typedef long result_type;
|
||||
|
||||
long operator() () const {
|
||||
return ::CORE::defRelPrec.toLong();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -181,8 +447,6 @@ template <> class Real_embeddable_traits< CORE::BigFloat >
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
//since types are included by CORE_coercion_traits.h:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
// Copyright (c) 2006-2007 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 <hemmer@mpi-inf.mpg.de>
|
||||
|
||||
|
||||
|
||||
#ifndef CGAL_CONVERT_TO_BFI_H
|
||||
#define CGAL_CONVERT_TO_BFI_H
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
#include <CGAL/Arithmetic_kernel.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
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 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 ?
|
||||
/*
|
||||
template <typename A,typename B> class Sqrt_extension;
|
||||
template <typename NT, typename ROOT>
|
||||
typename Get_arithmetic_kernel<NT>::Arithmetic_kernel::Bigfloat_interval
|
||||
convert_to_bfi(const CGAL::Sqrt_extension<NT,ROOT>& x) {
|
||||
typedef typename Get_arithmetic_kernel<NT>::Arithmetic_kernel AT;
|
||||
typedef typename AT::Bigfloat_interval BFI;
|
||||
if(x.is_extended()){
|
||||
BFI a0(convert_to_bfi(x.a0()));
|
||||
BFI a1(convert_to_bfi(x.a1()));
|
||||
BFI root(CGAL::sqrt(convert_to_bfi(x.root())));
|
||||
return a0+a1*root;
|
||||
}else{
|
||||
return convert_to_bfi(x.a0());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
#endif // CGAL_CONVERT_TO_BFI_H
|
||||
|
|
@ -1,310 +0,0 @@
|
|||
// 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>
|
||||
//
|
||||
// ============================================================================
|
||||
|
||||
// TODO:
|
||||
// - mv general functors in a new Interval_traits
|
||||
// - mv function 'round' to Interval_traits
|
||||
|
||||
#ifndef CGAL_CORE_INTERVAL_SUPPORT_H
|
||||
#define CGAL_CORE_INTERVAL_SUPPORT_H
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
#include <CGAL/interval_support.h>
|
||||
|
||||
#ifndef CGAL_USE_CORE
|
||||
#warning This header file needs CORE installed in order to work properly.
|
||||
#else // CGAL_USE_CORE
|
||||
|
||||
#include <CGAL/CORE/BigFloat.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
template<>
|
||||
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 CGAL::Tag_true Is_interval;
|
||||
|
||||
struct Lower :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator() ( Interval x ) const {
|
||||
CORE::BigFloat result = ::CORE::BigFloat(x.m()-x.err(),0,x.exp());
|
||||
CGAL_postcondition(result <= x);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct Upper :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator() ( Interval x ) const {
|
||||
CORE::BigFloat result = ::CORE::BigFloat(x.m()+x.err(),0,x.exp());
|
||||
CGAL_postcondition(result >= x);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct Width :public Unary_function<Interval,Boundary>{
|
||||
|
||||
Boundary operator() ( Interval x ) const {
|
||||
unsigned long err = 2*x.err();
|
||||
return Boundary(CORE::BigInt(err),0,x.exp());
|
||||
}
|
||||
};
|
||||
|
||||
struct Median :public Unary_function<Interval,Boundary>{
|
||||
|
||||
Boundary operator() ( Interval x ) const {
|
||||
return Boundary(x.m(),0,x.exp());
|
||||
}
|
||||
};
|
||||
|
||||
struct Norm :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator() ( Interval x ) const {
|
||||
return std::max(Upper()(x).abs(),Lower()(x).abs());
|
||||
}
|
||||
};
|
||||
|
||||
struct Zero_in :public Unary_function<Interval,bool>{
|
||||
bool operator() ( Interval x ) const {
|
||||
return x.isZeroIn();
|
||||
}
|
||||
};
|
||||
|
||||
struct In :public Binary_function<Boundary,Interval,bool>{
|
||||
bool operator()( Boundary x, const Interval& a ) const {
|
||||
CGAL_precondition(CGAL::singleton(x));
|
||||
return (Lower()(a) <= x && x <= Upper()(a));
|
||||
}
|
||||
};
|
||||
|
||||
struct Equal :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return (Upper()(a) == Upper()(b) && Lower()(a) == Lower()(b));
|
||||
}
|
||||
};
|
||||
|
||||
struct Subset :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return Lower()(b) <= Lower()(a) && Upper()(a) <= Upper()(b);
|
||||
}
|
||||
};
|
||||
|
||||
struct Proper_subset :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return Subset()(a,b) && (!Equal()(a,b));
|
||||
}
|
||||
};
|
||||
|
||||
struct Intersection :public Binary_function<Interval,Interval,Interval>{
|
||||
Interval operator()( const Interval& a, const Interval& b ) const {
|
||||
// std::cout <<"a= (" << a.m() << "+-" << a.err() << ")*2^" << a.exp() << std::endl;
|
||||
Boundary l(CGAL::max(Lower()(a),Lower()(b)));
|
||||
Boundary u(CGAL::min(Upper()(a),Upper()(b)));
|
||||
|
||||
if(u < l ) throw Exception_intersection_is_empty();
|
||||
return Construct()(l,u);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct Overlap :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator() ( Interval x, Interval y ) const {
|
||||
Self::Zero_in Zero_in;
|
||||
bool result = Zero_in(x-y);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct Hull :public Binary_function<Interval,Interval,Interval>{
|
||||
Interval operator() ( Interval x, Interval y ) const {
|
||||
#if 0
|
||||
// this is not possible since CORE::centerize has a bug.
|
||||
Interval result = CORE::centerize(x,y);
|
||||
#else
|
||||
|
||||
CORE::BigFloat result;
|
||||
|
||||
// Unfortunately, CORE::centerize(x,y) has bugs.
|
||||
if ((x.m() == y.m()) && (x.err() == y.err()) && (x.exp() == y.exp())) {
|
||||
return x;
|
||||
}
|
||||
|
||||
CORE::BigFloat lower = std::min(CGAL::lower(x), CGAL::lower(y));
|
||||
CORE::BigFloat upper = std::max(CGAL::upper(x), CGAL::upper(y));
|
||||
|
||||
CORE::BigFloat mid = (lower + upper)/2;
|
||||
|
||||
// Now we have to compute the error. The problem is that .err() is just a long
|
||||
CORE::BigFloat err = (upper - lower)/CORE::BigFloat(2);
|
||||
|
||||
//std::cout << "lower " << lower << std::endl;
|
||||
//std::cout << "upper " << upper << std::endl;
|
||||
//std::cout << "mid " << mid << std::endl;
|
||||
//std::cout << "err I " << err << std::endl;
|
||||
|
||||
// shift such that err.m()+err.err() fits into long
|
||||
int digits_long = std::numeric_limits<long>::digits;
|
||||
if(::CORE::bitLength(err.m()) >= digits_long){
|
||||
long shift = ::CORE::bitLength(err.m()) - digits_long + 1 ;
|
||||
//std::cout << "shift " << shift<< std::endl;
|
||||
long new_err = ((err.m()+err.err()) >> shift).longValue()+1;
|
||||
err = CORE::BigFloat(0,new_err,0) * CORE::BigFloat::exp2(err.exp()*14+shift);
|
||||
}else{
|
||||
err = CORE::BigFloat(0,err.m().longValue()+err.err(),err.exp());
|
||||
}
|
||||
|
||||
result = mid + err;
|
||||
|
||||
#endif
|
||||
CGAL_postcondition(
|
||||
CGAL::lower(result)
|
||||
<= std::min(CGAL::lower(x), CGAL::lower(y)));
|
||||
CGAL_postcondition(
|
||||
CGAL::upper(result)
|
||||
>= std::max(CGAL::upper(x), CGAL::upper(y)));
|
||||
|
||||
return result ;
|
||||
}
|
||||
};
|
||||
|
||||
struct Singleton :public Unary_function<Interval,bool> {
|
||||
bool operator() ( Interval x ) const {
|
||||
return (x.err() == 0);
|
||||
}
|
||||
};
|
||||
|
||||
struct Construct :public Binary_function<Boundary,Boundary,Interval>{
|
||||
Interval operator()( const Boundary& l,const Boundary& r) const {
|
||||
CGAL_precondition( l < r );
|
||||
return Hull()(l,r);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
// 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();
|
||||
|
||||
// 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()));
|
||||
CGAL_postcondition(BF(xr.m()+xr.err(),0,xr.exp()) >= BF(x.m()+x.err(),0,x.exp()));
|
||||
return xr;
|
||||
}
|
||||
|
||||
template<> class Bigfloat_interval_traits<CORE::BigFloat>
|
||||
:public Interval_traits<CORE::BigFloat>
|
||||
{
|
||||
public:
|
||||
typedef CORE::BigFloat NT;
|
||||
typedef CORE::BigFloat BF;
|
||||
|
||||
typedef Bigfloat_interval_traits<NT> Self;
|
||||
|
||||
// How about retuning
|
||||
struct Get_significant_bits {
|
||||
// type for the \c AdaptableUnaryFunction concept.
|
||||
typedef NT argument_type;
|
||||
// type for the \c AdaptableUnaryFunction concept.
|
||||
typedef long result_type;
|
||||
|
||||
long operator()( NT x) const {
|
||||
if(x.err() == 0 ) {
|
||||
return ::CORE::bitLength(x.m());
|
||||
}
|
||||
else {
|
||||
return ::CORE::bitLength(x.m()) - ::CORE::bitLength(x.err());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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 result = ::CORE::defRelPrec.toLong();
|
||||
::CORE::defRelPrec = prec;
|
||||
::CORE::defBFdivRelPrec = prec;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct Get_precision {
|
||||
// type for the \c AdaptableGenerator concept.
|
||||
typedef long result_type;
|
||||
|
||||
long operator() () const {
|
||||
return ::CORE::defRelPrec.toLong();
|
||||
}
|
||||
};
|
||||
|
||||
struct Convert_to_bfi {
|
||||
typedef NT result_type;
|
||||
|
||||
NT operator() (const ::CORE::Expr& x){
|
||||
return round(CORE::BigFloat(x));
|
||||
}
|
||||
|
||||
NT operator() (const ::CORE::BigInt& x){
|
||||
return round(CORE::BigFloat(x));
|
||||
}
|
||||
|
||||
NT operator() (const ::CORE::BigRat& x){
|
||||
return round(CORE::BigFloat(x));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
#endif // CGAL_USE_CORE
|
||||
#endif // CGAL_CORE_INTERVAL_SUPPORT_H
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
// 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_support.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_SUPPORT_H
|
||||
#define CGAL_INTERVAL_SUPPORT_H
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
#include <CGAL/Interval_traits.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
// This will go into bigfloat_interval_support.h
|
||||
//////////////////////////////// BFI Traits
|
||||
|
||||
|
||||
template<typename BigfloatInterval> class Bigfloat_interval_traits;
|
||||
|
||||
|
||||
template<typename BFI> inline long get_significant_bits(BFI bfi) {
|
||||
typename Bigfloat_interval_traits<BFI>::Get_significant_bits
|
||||
get_significant_bits;
|
||||
return get_significant_bits(bfi);
|
||||
}
|
||||
|
||||
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) {
|
||||
typename Bigfloat_interval_traits<BFI>::Get_precision get_precision;
|
||||
return get_precision();
|
||||
}
|
||||
|
||||
|
||||
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 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 ?
|
||||
template <typename A,typename B> class Sqrt_extension;
|
||||
template <typename NT, typename ROOT>
|
||||
typename Get_arithmetic_kernel<NT>::Arithmetic_kernel::Bigfloat_interval
|
||||
convert_to_bfi(const CGAL::Sqrt_extension<NT,ROOT>& x) {
|
||||
typedef typename Get_arithmetic_kernel<NT>::Arithmetic_kernel AT;
|
||||
typedef typename AT::Bigfloat_interval BFI;
|
||||
if(x.is_extended()){
|
||||
BFI a0(convert_to_bfi(x.a0()));
|
||||
BFI a1(convert_to_bfi(x.a1()));
|
||||
BFI root(CGAL::sqrt(convert_to_bfi(x.root())));
|
||||
return a0+a1*root;
|
||||
}else{
|
||||
return convert_to_bfi(x.a0());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
#include <CGAL/Arithmetic_kernel.h>
|
||||
|
||||
#endif // CGAL_INTERVAL_SUPPORT_H
|
||||
|
|
@ -17,11 +17,14 @@
|
|||
#include <LEDA/numbers/bigfloat.h>
|
||||
#endif
|
||||
|
||||
#include <boost/numeric/interval.hpp>
|
||||
|
||||
#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>
|
||||
#include <CGAL/Interval_traits.h>
|
||||
#include <CGAL/Bigfloat_interval_traits.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
namespace CGALi {
|
||||
|
|
@ -237,9 +240,10 @@ struct Coercion_traits< leda_bigfloat_interval , ::leda::rational >{
|
|||
typedef Type result_type;
|
||||
Type operator()(const leda_bigfloat_interval& x) const { return x;}
|
||||
Type operator()(const ::leda::rational x) const {
|
||||
long prec = ::leda::bigfloat::get_precision();
|
||||
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));
|
||||
leda_bigfloat::from_rational(x,prec,leda::TO_N_INF),
|
||||
leda_bigfloat::from_rational(x,prec,leda::TO_P_INF));
|
||||
CGAL_postcondition( result.lower() <= x );
|
||||
CGAL_postcondition( result.upper() >= x );
|
||||
return result;
|
||||
|
|
@ -260,7 +264,8 @@ struct Coercion_traits< leda_bigfloat_interval , ::leda::real >{
|
|||
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());
|
||||
leda_bigfloat_interval
|
||||
result(x.get_lower_bound(), x.get_upper_bound());
|
||||
CGAL_postcondition( result.lower() <= x );
|
||||
CGAL_postcondition( result.upper() >= x );
|
||||
return result;
|
||||
|
|
@ -279,6 +284,178 @@ template <> struct Coercion_traits< ::leda::real, leda_bigfloat_interval >
|
|||
|
||||
|
||||
|
||||
template<>
|
||||
class Interval_traits<leda_bigfloat_interval>
|
||||
{
|
||||
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 {
|
||||
CGAL_precondition( l < r );
|
||||
return Interval(l,r);
|
||||
}
|
||||
};
|
||||
|
||||
struct Lower :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator()( const Interval& a ) const {
|
||||
return a.lower();
|
||||
}
|
||||
};
|
||||
|
||||
struct Upper :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator()( const Interval& a ) const {
|
||||
return a.upper();
|
||||
}
|
||||
};
|
||||
|
||||
struct Width :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator()( const Interval& a ) const {
|
||||
return ::boost::numeric::width(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Median :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator()( const Interval& a ) const {
|
||||
return ::boost::numeric::median(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Norm :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator()( const Interval& a ) const {
|
||||
return ::boost::numeric::norm(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Empty :public Unary_function<Interval,bool>{
|
||||
bool operator()( const Interval& a ) const {
|
||||
return ::boost::numeric::empty(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Singleton :public Unary_function<Interval,bool>{
|
||||
bool operator()( const Interval& a ) const {
|
||||
return ::boost::numeric::singleton(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Zero_in :public Unary_function<Interval,bool>{
|
||||
bool operator()( const Interval& a ) const {
|
||||
return ::boost::numeric::in_zero(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct In :public Binary_function<Boundary,Interval,bool>{
|
||||
bool operator()( Boundary x, const Interval& a ) const {
|
||||
return ::boost::numeric::in(x,a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Equal :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return ::boost::numeric::equal(a,b);
|
||||
}
|
||||
};
|
||||
|
||||
struct Overlap :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return ::boost::numeric::overlap(a,b);
|
||||
}
|
||||
};
|
||||
|
||||
struct Subset :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return ::boost::numeric::subset(a,b);
|
||||
}
|
||||
};
|
||||
|
||||
struct Proper_subset :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return ::boost::numeric::proper_subset(a,b);
|
||||
}
|
||||
};
|
||||
|
||||
struct Hull :public Binary_function<Interval,Interval,Interval>{
|
||||
Interval operator()( const Interval& a, const Interval& b ) const {
|
||||
return ::boost::numeric::hull(a,b);
|
||||
}
|
||||
};
|
||||
|
||||
struct Intersection :public Binary_function<Interval,Interval,Interval>{
|
||||
Interval operator()( const Interval& a, const Interval& b ) const {
|
||||
Interval r = ::boost::numeric::intersect(a,b);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class Bigfloat_interval_traits<leda_bigfloat_interval>
|
||||
:public Interval_traits<leda_bigfloat_interval>
|
||||
{
|
||||
|
||||
public:
|
||||
typedef Bigfloat_interval_traits<leda_bigfloat_interval> Self;
|
||||
typedef leda_bigfloat_interval NT;
|
||||
typedef leda::bigfloat BF;
|
||||
|
||||
struct Get_significant_bits : public Unary_function<NT,long>{
|
||||
|
||||
long operator()( NT x) const {
|
||||
leda::bigfloat lower = x.lower();
|
||||
leda::bigfloat upper = x.upper();
|
||||
|
||||
leda::integer lower_m = lower.get_significant();
|
||||
leda::integer upper_m = upper.get_significant();
|
||||
|
||||
leda::integer lower_exp = lower.get_exponent();
|
||||
leda::integer upper_exp = upper.get_exponent();
|
||||
|
||||
long shift = (upper_exp - lower_exp).to_long();
|
||||
if(shift >= 0 ) upper_m = (upper_m << shift);
|
||||
else lower_m = (lower_m << -shift);
|
||||
|
||||
//CGAL_postcondition(lower_m.length() == upper_m.length());
|
||||
|
||||
leda::integer err = lower_m-upper_m;
|
||||
|
||||
return std::max(lower_m.length()-err.length(),0);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
struct Set_precision : public Unary_function<long,long> {
|
||||
long operator()( long prec ) const {
|
||||
return BF::set_precision(prec);
|
||||
}
|
||||
};
|
||||
|
||||
struct Get_precision {
|
||||
// type for the \c AdaptableGenerator concept.
|
||||
typedef long result_type;
|
||||
long operator()() const {
|
||||
return BF::get_precision();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
::leda::bigfloat inline relative_error(const leda_bigfloat_interval& x){
|
||||
if(in_zero(x)){
|
||||
return CGAL::abs(x).upper();
|
||||
}else{
|
||||
return (width(x) / CGAL::abs(x)).upper();
|
||||
}
|
||||
}
|
||||
|
||||
leda_bigfloat_interval inline ipower(const leda_bigfloat_interval& x, int i ){
|
||||
return ::boost::numeric::pow(x,i);
|
||||
}
|
||||
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
#endif // CGAL_USE_LEDA
|
||||
|
|
|
|||
|
|
@ -1,279 +0,0 @@
|
|||
// TODO:
|
||||
// - add to comming interval_traits:
|
||||
// -- CGAL::median(bf_interval)
|
||||
// -- CGAL::ipower(bf_interval)
|
||||
// -- CGAL::relatoive_error(bf_interval)
|
||||
|
||||
/*! \file CGAL/leda_interval_support.h
|
||||
*/
|
||||
|
||||
#ifndef CGAL_LEDA_INTERVAL_SUPPORT_H
|
||||
#define CGAL_LEDA_INTERVAL_SUPPORT_H
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
|
||||
#ifndef CGAL_USE_LEDA
|
||||
#warning This header file needs LEDA installed in order to work properly.
|
||||
#else // CGAL_USE_LEDA
|
||||
|
||||
#include <CGAL/leda_bigfloat.h>
|
||||
#include <CGAL/leda_integer.h>
|
||||
#include <CGAL/leda_rational.h>
|
||||
#include <CGAL/leda_real.h>
|
||||
#include <CGAL/leda_bigfloat_interval.h>
|
||||
|
||||
|
||||
#include <CGAL/interval_support.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
template<>
|
||||
class Interval_traits<leda_bigfloat_interval>
|
||||
{
|
||||
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 {
|
||||
CGAL_precondition( l < r );
|
||||
return Interval(l,r);
|
||||
}
|
||||
};
|
||||
|
||||
struct Lower :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator()( const Interval& a ) const {
|
||||
return a.lower();
|
||||
}
|
||||
};
|
||||
|
||||
struct Upper :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator()( const Interval& a ) const {
|
||||
return a.upper();
|
||||
}
|
||||
};
|
||||
|
||||
struct Width :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator()( const Interval& a ) const {
|
||||
return ::boost::numeric::width(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Median :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator()( const Interval& a ) const {
|
||||
return ::boost::numeric::median(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Norm :public Unary_function<Interval,Boundary>{
|
||||
Boundary operator()( const Interval& a ) const {
|
||||
return ::boost::numeric::norm(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Empty :public Unary_function<Interval,bool>{
|
||||
bool operator()( const Interval& a ) const {
|
||||
return ::boost::numeric::empty(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Singleton :public Unary_function<Interval,bool>{
|
||||
bool operator()( const Interval& a ) const {
|
||||
return ::boost::numeric::singleton(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Zero_in :public Unary_function<Interval,bool>{
|
||||
bool operator()( const Interval& a ) const {
|
||||
return ::boost::numeric::in_zero(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct In :public Binary_function<Boundary,Interval,bool>{
|
||||
bool operator()( Boundary x, const Interval& a ) const {
|
||||
return ::boost::numeric::in(x,a);
|
||||
}
|
||||
};
|
||||
|
||||
struct Equal :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return ::boost::numeric::equal(a,b);
|
||||
}
|
||||
};
|
||||
|
||||
struct Overlap :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return ::boost::numeric::overlap(a,b);
|
||||
}
|
||||
};
|
||||
|
||||
struct Subset :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return ::boost::numeric::subset(a,b);
|
||||
}
|
||||
};
|
||||
|
||||
struct Proper_subset :public Binary_function<Interval,Interval,bool>{
|
||||
bool operator()( const Interval& a, const Interval& b ) const {
|
||||
return ::boost::numeric::proper_subset(a,b);
|
||||
}
|
||||
};
|
||||
|
||||
struct Hull :public Binary_function<Interval,Interval,Interval>{
|
||||
Interval operator()( const Interval& a, const Interval& b ) const {
|
||||
return ::boost::numeric::hull(a,b);
|
||||
}
|
||||
};
|
||||
|
||||
struct Intersection :public Binary_function<Interval,Interval,Interval>{
|
||||
Interval operator()( const Interval& a, const Interval& b ) const {
|
||||
Interval r = ::boost::numeric::intersect(a,b);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
class Bigfloat_interval_traits<leda_bigfloat_interval>
|
||||
:public Interval_traits<leda_bigfloat_interval>
|
||||
{
|
||||
|
||||
public:
|
||||
typedef Bigfloat_interval_traits<leda_bigfloat_interval> Self;
|
||||
typedef leda_bigfloat_interval NT;
|
||||
typedef leda::bigfloat BF;
|
||||
|
||||
struct Get_significant_bits : public Unary_function<NT,long>{
|
||||
|
||||
long operator()( NT x) const {
|
||||
leda::bigfloat lower = x.lower();
|
||||
leda::bigfloat upper = x.upper();
|
||||
|
||||
leda::integer lower_m = lower.get_significant();
|
||||
leda::integer upper_m = upper.get_significant();
|
||||
|
||||
leda::integer lower_exp = lower.get_exponent();
|
||||
leda::integer upper_exp = upper.get_exponent();
|
||||
|
||||
long shift = (upper_exp - lower_exp).to_long();
|
||||
if(shift >= 0 ) upper_m = (upper_m << shift);
|
||||
else lower_m = (lower_m << -shift);
|
||||
|
||||
//CGAL_postcondition(lower_m.length() == upper_m.length());
|
||||
|
||||
leda::integer err = lower_m-upper_m;
|
||||
|
||||
return std::max(lower_m.length()-err.length(),0);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
struct Set_precision : public Unary_function<long,long> {
|
||||
long operator()( long prec ) const {
|
||||
return BF::set_precision(prec);
|
||||
}
|
||||
};
|
||||
|
||||
struct Get_precision {
|
||||
// type for the \c AdaptableGenerator concept.
|
||||
typedef long result_type;
|
||||
long operator()() const {
|
||||
return BF::get_precision();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
struct Convert_to_bfi {
|
||||
|
||||
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);
|
||||
|
||||
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) ;
|
||||
|
||||
// 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 );
|
||||
|
||||
return bfi;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
::leda::bigfloat inline relative_error(const leda_bigfloat_interval& x){
|
||||
if(in_zero(x)){
|
||||
return CGAL::abs(x).upper();
|
||||
}else{
|
||||
return (width(x) / CGAL::abs(x)).upper();
|
||||
}
|
||||
}
|
||||
|
||||
leda_bigfloat_interval inline ipower(const leda_bigfloat_interval& x, int i ){
|
||||
return ::boost::numeric::pow(x,i);
|
||||
}
|
||||
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
#endif // CGAL_USE_LEDA
|
||||
#endif // CGAL_LEDA_INTERVAL_SUPPORT_H
|
||||
Loading…
Reference in New Issue