BWAPI
|
00001 // Copyright (c) 1999 Utrecht University (The Netherlands), 00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany), 00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg 00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), 00005 // and Tel-Aviv University (Israel). All rights reserved. 00006 // 00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00008 // modify it under the terms of the GNU Lesser General Public License as 00009 // published by the Free Software Foundation; version 2.1 of the License. 00010 // See the file LICENSE.LGPL distributed with CGAL. 00011 // 00012 // Licensees holding a valid commercial license may use this file in 00013 // accordance with the commercial license agreement provided with the software. 00014 // 00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 // 00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Algebraic_foundations/include/CGAL/number_utils.h $ 00019 // $Id: number_utils.h 45636 2008-09-18 15:35:55Z hemmer $ 00020 // 00021 // 00022 // Author(s) : Stefan Schirra 00023 00024 #ifndef CGAL_NUMBER_UTILS_H 00025 #define CGAL_NUMBER_UTILS_H 00026 00027 #include <CGAL/number_type_basic.h> 00028 00029 CGAL_BEGIN_NAMESPACE 00030 CGAL_NTS_BEGIN_NAMESPACE 00031 00032 00033 // AST-Functor adapting functions UNARY 00034 template< class AS > 00035 inline 00036 void 00037 simplify( AS& x ) { 00038 typename Algebraic_structure_traits< AS >::Simplify simplify; 00039 simplify( x ); 00040 } 00041 00042 template< class AS > 00043 inline 00044 typename Algebraic_structure_traits< AS >::Unit_part::result_type 00045 unit_part( const AS& x ) { 00046 typename Algebraic_structure_traits< AS >::Unit_part unit_part; 00047 return unit_part( x ); 00048 } 00049 00050 00051 template< class AS > 00052 inline 00053 typename Algebraic_structure_traits< AS >::Is_square::result_type 00054 is_square( const AS& x, 00055 typename Algebraic_structure_traits< AS >::Is_square::second_argument_type y ) 00056 { 00057 typename Algebraic_structure_traits< AS >::Is_square is_square; 00058 return is_square( x, y ); 00059 } 00060 00061 template< class AS > 00062 inline 00063 typename Algebraic_structure_traits< AS >::Is_square::result_type 00064 is_square( const AS& x){ 00065 typename Algebraic_structure_traits< AS >::Is_square is_square; 00066 return is_square( x ); 00067 } 00068 00069 00070 template< class AS > 00071 inline 00072 typename Algebraic_structure_traits< AS >::Square::result_type 00073 square( const AS& x ) { 00074 typename Algebraic_structure_traits< AS >::Square square; 00075 return square( x ); 00076 } 00077 template< class AS > 00078 inline 00079 typename Algebraic_structure_traits<AS>::Is_one::result_type 00080 is_one( const AS& x ) { 00081 typename Algebraic_structure_traits< AS >::Is_one is_one; 00082 return is_one( x ); 00083 } 00084 00085 template< class AS > 00086 inline 00087 typename Algebraic_structure_traits< AS >::Sqrt::result_type 00088 sqrt( const AS& x ) { 00089 typename Algebraic_structure_traits< AS >::Sqrt sqrt; 00090 return sqrt( x ); 00091 } 00092 00093 00094 00095 // AST-Functor adapting functions BINARY 00096 00097 template< class A, class B > 00098 inline 00099 typename Algebraic_structure_traits< typename Coercion_traits<A,B>::Type> 00100 ::Integral_division::result_type 00101 integral_division( const A& x, const B& y ) { 00102 typedef typename Coercion_traits<A,B>::Type Type; 00103 typename Algebraic_structure_traits< Type >::Integral_division 00104 integral_division; 00105 return integral_division( x, y ); 00106 } 00107 00108 template< class A, class B > 00109 inline 00110 typename Algebraic_structure_traits< typename Coercion_traits<A,B>::Type> 00111 ::Divides::result_type 00112 divides( const A& x, const B& y ) { 00113 typedef typename Coercion_traits<A,B>::Type Type; 00114 typename Algebraic_structure_traits< Type >::Divides divides; 00115 return divides( x, y ); 00116 } 00117 00118 template< class Type > 00119 inline 00120 typename Algebraic_structure_traits<Type>::Divides::result_type 00121 divides( const Type& x, const Type& y, Type& q ) { 00122 typename Algebraic_structure_traits< Type >::Divides divides; 00123 return divides( x, y, q); 00124 } 00125 00126 template< class A, class B > 00127 inline 00128 typename Algebraic_structure_traits< typename Coercion_traits<A,B>::Type > 00129 ::Gcd::result_type 00130 gcd( const A& x, const B& y ) { 00131 typedef typename Coercion_traits<A,B>::Type Type; 00132 typename Algebraic_structure_traits< Type >::Gcd gcd; 00133 return gcd( x, y ); 00134 } 00135 00136 00137 template< class A, class B > 00138 inline 00139 typename Algebraic_structure_traits< typename Coercion_traits<A,B>::Type > 00140 ::Mod::result_type 00141 mod( const A& x, const B& y ) { 00142 typedef typename Coercion_traits<A,B>::Type Type; 00143 typename Algebraic_structure_traits<Type >::Mod mod; 00144 return mod( x, y ); 00145 } 00146 00147 template< class A, class B > 00148 inline 00149 typename Algebraic_structure_traits< typename Coercion_traits<A,B>::Type>::Div::result_type 00150 div( const A& x, const B& y ) { 00151 typedef typename Coercion_traits<A,B>::Type Type; 00152 typename Algebraic_structure_traits<Type >::Div div; 00153 return div( x, y ); 00154 } 00155 00156 template< class A, class B > 00157 inline 00158 void 00159 div_mod( 00160 const A& x, 00161 const B& y, 00162 typename Coercion_traits<A,B>::Type& q, 00163 typename Coercion_traits<A,B>::Type& r ) { 00164 typedef typename Coercion_traits<A,B>::Type Type; 00165 typename Algebraic_structure_traits< Type >::Div_mod div_mod; 00166 div_mod( x, y, q, r ); 00167 } 00168 00169 // others 00170 template< class AS > 00171 inline 00172 typename Algebraic_structure_traits< AS >::Kth_root::result_type 00173 kth_root( int k, const AS& x ) { 00174 typename Algebraic_structure_traits< AS >::Kth_root 00175 kth_root; 00176 return kth_root( k, x ); 00177 } 00178 00179 00180 template< class Input_iterator > 00181 inline 00182 typename Algebraic_structure_traits< typename std::iterator_traits<Input_iterator>::value_type > 00183 ::Root_of::result_type 00184 root_of( int k, Input_iterator begin, Input_iterator end ) { 00185 typedef typename std::iterator_traits<Input_iterator>::value_type AS; 00186 return typename Algebraic_structure_traits<AS>::Root_of()( k, begin, end ); 00187 } 00188 00189 // AST- and RET-functor adapting function 00190 template< class Number_type > 00191 inline 00192 // select a Is_zero functor 00193 typename boost::mpl::if_c< 00194 ::boost::is_same< typename Algebraic_structure_traits< Number_type >::Is_zero, 00195 Null_functor >::value , 00196 typename Real_embeddable_traits< Number_type >::Is_zero, 00197 typename Algebraic_structure_traits< Number_type >::Is_zero 00198 >::type::result_type 00199 is_zero( const Number_type& x ) { 00200 // We take the Algebraic_structure_traits<>::Is_zero functor by default. If it 00201 // is not available, we take the Real_embeddable_traits functor 00202 typename ::boost::mpl::if_c< 00203 ::boost::is_same< 00204 typename Algebraic_structure_traits< Number_type >::Is_zero, 00205 Null_functor >::value , 00206 typename Real_embeddable_traits< Number_type >::Is_zero, 00207 typename Algebraic_structure_traits< Number_type >::Is_zero >::type 00208 is_zero; 00209 return is_zero( x ); 00210 } 00211 00212 00213 template <class A, class B> 00214 inline 00215 typename Real_embeddable_traits< typename Coercion_traits<A,B>::Type > 00216 ::Compare::result_type 00217 compare(const A& a, const B& b) 00218 { 00219 typedef typename Coercion_traits<A,B>::Type Type; 00220 typename Real_embeddable_traits<Type>::Compare compare; 00221 return compare (a,b); 00222 // return (a < b) ? SMALLER : (b < a) ? LARGER : EQUAL; 00223 } 00224 00225 00226 // RET-Functor adapting functions 00227 template< class Real_embeddable > 00228 inline 00229 //Real_embeddable 00230 typename Real_embeddable_traits< Real_embeddable >::Abs::result_type 00231 abs( const Real_embeddable& x ) { 00232 typename Real_embeddable_traits< Real_embeddable >::Abs abs; 00233 return abs( x ); 00234 } 00235 00236 template< class Real_embeddable > 00237 inline 00238 //::Sign 00239 typename Real_embeddable_traits< Real_embeddable >::Sgn::result_type 00240 sign( const Real_embeddable& x ) { 00241 typename Real_embeddable_traits< Real_embeddable >::Sgn sgn; 00242 return sgn( x ); 00243 } 00244 00245 template< class Real_embeddable > 00246 inline 00247 //bool 00248 typename Real_embeddable_traits< Real_embeddable >::Is_finite::result_type 00249 is_finite( const Real_embeddable& x ) { 00250 return typename Real_embeddable_traits< Real_embeddable >::Is_finite()( x ); 00251 } 00252 00253 template< class Real_embeddable > 00254 inline 00255 typename Real_embeddable_traits< Real_embeddable >::Is_positive::result_type 00256 is_positive( const Real_embeddable& x ) { 00257 typename Real_embeddable_traits< Real_embeddable >::Is_positive 00258 is_positive; 00259 return is_positive( x ); 00260 } 00261 00262 template< class Real_embeddable > 00263 inline 00264 typename Real_embeddable_traits< Real_embeddable >::Is_negative::result_type 00265 is_negative( const Real_embeddable& x ) { 00266 typename Real_embeddable_traits< Real_embeddable >::Is_negative 00267 is_negative; 00268 return is_negative( x ); 00269 } 00270 00271 /* 00272 template< class Real_embeddable > 00273 inline 00274 typename Real_embeddable_traits< Real_embeddable >::Compare::result_type 00275 //Comparison_result 00276 compare( const Real_embeddable& x, const Real_embeddable& y ) { 00277 typename Real_embeddable_traits< Real_embeddable >::Compare compare; 00278 return compare( x, y ); 00279 } 00280 */ 00281 00282 template< class Real_embeddable > 00283 inline 00284 typename Real_embeddable_traits< Real_embeddable >::To_double::result_type 00285 //double 00286 to_double( const Real_embeddable& x ) { 00287 typename Real_embeddable_traits< Real_embeddable >::To_double to_double; 00288 return to_double( x ); 00289 } 00290 00291 template< class Real_embeddable > 00292 inline 00293 typename Real_embeddable_traits< Real_embeddable >::To_interval::result_type 00294 //std::pair< double, double > 00295 to_interval( const Real_embeddable& x) { 00296 typename Real_embeddable_traits< Real_embeddable >::To_interval 00297 to_interval; 00298 return to_interval( x ); 00299 } 00300 00301 00302 CGAL_NTS_END_NAMESPACE 00303 CGAL_END_NAMESPACE 00304 00305 #endif // CGAL_NUMBER_UTILS_H