// Copyright (c) 2006-2009 Max-Planck-Institute Saarbruecken (Germany), // INRIA Sophia-Antipolis (France). // 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 #ifndef CGAL_CONVERT_TO_BFI_H #define CGAL_CONVERT_TO_BFI_H #include #include #include CGAL_BEGIN_NAMESPACE template typename Get_arithmetic_kernel::Arithmetic_kernel::Bigfloat_interval convert_to_bfi(const NTX& x) { typedef typename Get_arithmetic_kernel::Arithmetic_kernel AK; typedef typename AK::Bigfloat_interval BFI; typedef CGAL::Coercion_traits CT; return typename CT::Cast()(x); // typedef typename Get_arithmetic_kernel::Arithmetic_kernel AT; // typedef typename AT::Bigfloat_interval BFI; // typename Bigfloat_interval_traits::Convert_to_bfi convert_to_bfi; // return convert_to_bfi(x); } // Disbale SQRT_EXTENSION_TO_BFI_CACHE by default #ifndef CGAL_USE_SQRT_EXTENSION_TO_BFI_CACHE #define CGAL_USE_SQRT_EXTENSION_TO_BFI_CACHE 0 #endif #if CGAL_USE_SQRT_EXTENSION_TO_BFI_CACHE namespace INTERN_SQRT_EXTENSION { template class Sqrt_extension_bfi_cache { typedef std::pair Input; typedef BFI Output; typedef typename Coercion_traits::Cast Cast; typedef typename Algebraic_structure_traits::Sqrt Sqrt; struct Creator : public std::unary_function { BFI operator()(const Input& pair){ return Sqrt()(Cast()(pair.second)); } }; } public: typedef Cache Cache_type; static Cache_type cache; }; template typename Sqrt_extension_bfi_cache::Cache_type Sqrt_extension_bfi_cache::cache; } // namespace INTERN_SQRT_EXTENSION // TODO: move this to sqrt_extension ? template class Sqrt_extension; template typename Get_arithmetic_kernel::Arithmetic_kernel::Bigfloat_interval convert_to_bfi(const CGAL::Sqrt_extension& x) { typedef typename Get_arithmetic_kernel::Arithmetic_kernel AK; typedef typename AK::Bigfloat_interval BFI; typedef Bigfloat_interval_traits BFIT; long precision = typename BFIT::Get_precision()(); BFI result; if(x.is_extended()){ typedef INTERN_SQRT_EXTENSION::Sqrt_extension_bfi_cache Get_cache; BFI a0(convert_to_bfi(x.a0())); BFI a1(convert_to_bfi(x.a1())); BFI root(Get_cache::cache(std::make_pair(precision,x.root()))); result = a0+a1*root; }else{ result = convert_to_bfi(x.a0()); } #ifndef NDEBUG BFI result_; typedef typename Get_arithmetic_kernel::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()))); result_ = a0+a1*root; }else{ result_ = convert_to_bfi(x.a0()); } assert(lower(result) == lower(result_)); assert(upper(result) == upper(result_)); #endif return result; } #endif CGAL_END_NAMESPACE #endif // CGAL_CONVERT_TO_BFI_H