|
BWAPI
|
00001 00002 // Copyright (c) 1999,2007 Utrecht University (The Netherlands), 00003 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany), 00004 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg 00005 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), 00006 // and Tel-Aviv University (Israel). All rights reserved. 00007 // 00008 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00009 // modify it under the terms of the GNU Lesser General Public License as 00010 // published by the Free Software Foundation; version 2.1 of the License. 00011 // See the file LICENSE.LGPL distributed with CGAL. 00012 // 00013 // Licensees holding a valid commercial license may use this file in 00014 // accordance with the commercial license agreement provided with the software. 00015 // 00016 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00017 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00018 // 00019 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Number_types/include/CGAL/leda_bigfloat.h $ 00020 // $Id: leda_bigfloat.h 45636 2008-09-18 15:35:55Z hemmer $ 00021 // 00022 // 00023 // Author(s) : Stefan Schirra, Michael Hemmer 00024 00025 #ifndef CGAL_LEDA_BIGFLOAT_H 00026 #define CGAL_LEDA_BIGFLOAT_H 00027 00028 #include <CGAL/basic.h> 00029 00030 #ifdef CGAL_USE_LEDA 00031 00032 #include <utility> 00033 #include <CGAL/leda_coercion_traits.h> 00034 #include <CGAL/Interval_nt.h> 00035 00036 #include <CGAL/LEDA_basic.h> 00037 #if CGAL_LEDA_VERSION < 500 00038 #include <LEDA/bigfloat.h> 00039 #else 00040 #include <LEDA/numbers/bigfloat.h> 00041 #endif 00042 00043 CGAL_BEGIN_NAMESPACE 00044 00045 template <> class Algebraic_structure_traits< leda_bigfloat > 00046 : public Algebraic_structure_traits_base< leda_bigfloat, 00047 Field_with_kth_root_tag > { 00048 public: 00049 typedef Tag_false Is_exact; 00050 typedef Tag_true Is_numerical_sensitive; 00051 00052 class Sqrt 00053 : public std::unary_function< Type, Type > { 00054 public: 00055 Type operator()( const Type& x ) const { 00056 return CGAL_LEDA_SCOPE::sqrt( x ); 00057 } 00058 }; 00059 00060 class Kth_root 00061 : public std::binary_function<int, Type, Type> { 00062 public: 00063 Type operator()( int k, 00064 const Type& x) const { 00065 CGAL_precondition_msg(k > 0, "'k' must be positive for k-th roots"); 00066 // heuristic: we ask for as many precision as the argument has 00067 long d = x.get_significant_length(); 00068 if ( d < 53) // O.K. we want at least double precision 00069 d = 53; 00070 return CGAL_LEDA_SCOPE::sqrt_d( x, d, k); 00071 } 00072 }; 00073 00074 }; 00075 00076 template <> class Real_embeddable_traits< leda_bigfloat > 00077 : public INTERN_RET::Real_embeddable_traits_base< leda_bigfloat , CGAL::Tag_true > { 00078 public: 00079 00080 class Abs 00081 : public std::unary_function< Type, Type > { 00082 public: 00083 Type operator()( const Type& x ) const { 00084 return CGAL_LEDA_SCOPE::abs( x ); 00085 } 00086 }; 00087 00088 class Sgn 00089 : public std::unary_function< Type, ::CGAL::Sign > { 00090 public: 00091 ::CGAL::Sign operator()( const Type& x ) const { 00092 return (::CGAL::Sign) CGAL_LEDA_SCOPE::sign( x ); 00093 } 00094 }; 00095 00096 class Compare 00097 : public std::binary_function< Type, Type, 00098 Comparison_result > { 00099 public: 00100 Comparison_result operator()( const Type& x, 00101 const Type& y ) const { 00102 return (Comparison_result) CGAL_LEDA_SCOPE::compare( x, y ); 00103 } 00104 00105 CGAL_IMPLICIT_INTEROPERABLE_BINARY_OPERATOR_WITH_RT( Type, 00106 Comparison_result ); 00107 }; 00108 00109 class To_double 00110 : public std::unary_function< Type, double > { 00111 public: 00112 double operator()( const Type& x ) const { 00113 return x.to_double(); 00114 } 00115 }; 00116 00117 class To_interval 00118 : public std::unary_function< Type, std::pair< double, double > > { 00119 public: 00120 std::pair<double, double> operator()( const Type& x ) const { 00121 00122 // assuming leda_bigfloat guarantee 1 bit error max 00123 Protect_FPU_rounding<true> P (CGAL_FE_TONEAREST); 00124 Interval_nt_advanced approx (CGAL_LEDA_SCOPE::to_double(x)); 00125 FPU_set_cw(CGAL_FE_UPWARD); 00126 approx += Interval_nt<false>::smallest(); 00127 return approx.pair(); 00128 } 00129 }; 00130 00131 class Is_finite 00132 : public std::unary_function< Type, bool > { 00133 public: 00134 bool operator()( const Type& x ) const { 00135 return !( CGAL_LEDA_SCOPE::isInf(x) || CGAL_LEDA_SCOPE::isNaN(x) ); 00136 } 00137 }; 00138 }; 00139 00140 template<> 00141 class Is_valid< leda_bigfloat > 00142 : public std::unary_function< leda_bigfloat, bool > { 00143 public : 00144 bool operator()( const leda_bigfloat& x ) const { 00145 return !( CGAL_LEDA_SCOPE::isNaN(x) ); 00146 } 00147 }; 00148 00149 00150 CGAL_END_NAMESPACE 00151 00152 // Unary + is missing for leda::bigfloat 00153 namespace leda { 00154 inline bigfloat operator+( const bigfloat& i) { return i; } 00155 } // namespace leda 00156 00157 //since types are included by leda_coercion_traits.h: 00158 #include <CGAL/leda_integer.h> 00159 #include <CGAL/leda_rational.h> 00160 #include <CGAL/leda_bigfloat.h> 00161 #include <CGAL/leda_real.h> 00162 00163 #endif // CGAL_USE_LEDA 00164 00165 #endif // CGAL_LEDA_BIGFLOAT_H
1.7.6.1