|
BWAPI
|
00001 // Copyright (c) 2006-2008 Max-Planck-Institute Saarbruecken (Germany). 00002 // All rights reserved. 00003 // 00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License as 00006 // published by the Free Software Foundation; version 2.1 of the License. 00007 // See the file LICENSE.LGPL distributed with CGAL. 00008 // 00009 // Licensees holding a valid commercial license may use this file in 00010 // accordance with the commercial license agreement provided with the software. 00011 // 00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00014 // 00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Number_types/include/CGAL/CORE_BigInt.h $ 00016 // $Id: CORE_BigInt.h 48598 2009-03-31 17:20:16Z pmachado $ 00017 // 00018 // 00019 // Author(s) : Michael Hemmer <hemmer@mpi-inf.mpg.de> 00020 00021 00022 #ifndef CGAL_CORE_BIGINT_H 00023 #define CGAL_CORE_BIGINT_H 00024 00025 #include <CGAL/number_type_basic.h> 00026 #include <CGAL/CORE_coercion_traits.h> 00027 00028 #include <CGAL/Residue.h> 00029 #include <CGAL/Modular_traits.h> 00030 00031 CGAL_BEGIN_NAMESPACE 00032 00033 template<> 00034 struct Root_of_traits<CORE::BigInt>: public CGALi::Root_of_traits_helper<CORE::BigInt, 00035 Euclidean_ring_tag>{ 00036 typedef CORE::BigRat RootOf_1; 00037 typedef CORE::BigRat Root_of_1; 00038 }; 00039 00040 // 00041 // Algebraic structure traits 00042 // 00043 template <> class Algebraic_structure_traits< CORE::BigInt > 00044 : public Algebraic_structure_traits_base< CORE::BigInt, 00045 Euclidean_ring_tag > { 00046 public: 00047 typedef Tag_true Is_exact; 00048 typedef Tag_false Is_numerical_sensitive; 00049 00050 typedef INTERN_AST::Is_square_per_sqrt< Type > 00051 Is_square; 00052 00053 typedef INTERN_AST::Div_per_operator< Type > Div; 00054 typedef INTERN_AST::Mod_per_operator< Type > Mod; 00055 00056 class Sqrt 00057 : public std::unary_function< Type, Type > { 00058 public: 00060 Type operator()( const Type& x) const { 00061 Type result; 00062 mpz_sqrt(result.get_mp(), x.get_mp()); 00063 return result; 00064 } 00065 }; 00066 00067 00068 class Gcd 00069 : public std::binary_function< Type, Type, 00070 Type > { 00071 public: 00072 Type operator()( const Type& x, 00073 const Type& y) const { 00074 if ( x == Type(0) && y == Type(0) ) 00075 return Type(0); 00076 Type result; 00077 mpz_gcd(result.get_mp(), x.get_mp(), y.get_mp()); 00078 return result; 00079 } 00080 }; 00081 }; 00082 00083 // 00084 // Real embeddable traits 00085 // 00086 template <> class Real_embeddable_traits< CORE::BigInt > 00087 : public INTERN_RET::Real_embeddable_traits_base< CORE::BigInt , CGAL::Tag_true > { 00088 00089 public: 00090 00091 class Abs 00092 : public std::unary_function< Type, Type > { 00093 public: 00094 Type operator()( const Type& x ) const { 00095 return CORE::abs( x ); 00096 } 00097 }; 00098 00099 class Sgn 00100 : public std::unary_function< Type, ::CGAL::Sign > { 00101 public: 00102 ::CGAL::Sign operator()( const Type& x ) const { 00103 return (::CGAL::Sign) CORE::sign( x ); 00104 } 00105 }; 00106 00107 class Compare 00108 : public std::binary_function< Type, Type, 00109 Comparison_result > { 00110 public: 00111 Comparison_result operator()( const Type& x, 00112 const Type& y ) const { 00113 return CGAL::sign(::CORE::cmp(x,y)); 00114 } 00115 }; 00116 00117 class To_double 00118 : public std::unary_function< Type, double > { 00119 public: 00120 double operator()( const Type& x ) const { 00121 // this call is required to get reasonable values for the double 00122 // approximation 00123 return x.doubleValue(); 00124 } 00125 }; 00126 00127 class To_interval 00128 : public std::unary_function< Type, std::pair< double, double > > { 00129 public: 00130 std::pair<double, double> operator()( const Type& x_ ) const { 00131 CORE::Expr x(x_); 00132 std::pair<double,double> result; 00133 x.doubleInterval(result.first, result.second); 00134 CGAL_expensive_assertion(result.first <= x); 00135 CGAL_expensive_assertion(result.second >= x); 00136 return result; 00137 } 00138 }; 00139 }; 00140 00145 template<> 00146 class Modular_traits< ::CORE::BigInt > { 00147 typedef Residue RES; 00148 public: 00149 typedef ::CORE::BigInt NT; 00150 typedef CGAL::Tag_true Is_modularizable; 00151 typedef Residue Residue_type; 00152 00153 struct Modular_image{ 00154 Residue_type operator()(const NT& a){ 00155 NT tmp = a % NT(RES::get_current_prime()); 00156 // TODO: reactivate this assertion 00157 // it fails with core_v1.6x_20040329 00158 // NiX_assert(tmp.isInt()); 00159 int mi(tmp.longValue()); 00160 if (mi < 0) mi += RES::get_current_prime(); 00161 return Residue_type(mi); 00162 } 00163 }; 00164 struct Modular_image_representative{ 00165 NT operator()(const Residue_type& x){ 00166 return NT(x.get_value()); 00167 } 00168 }; 00169 }; 00170 00171 00172 template<> 00173 struct Needs_parens_as_product<CORE::BigInt>{ 00174 bool operator()(const CORE::BigInt& x){ 00175 return CGAL_NTS is_negative(x); 00176 } 00177 }; 00178 00179 // Benchmark_rep specialization 00180 template<> 00181 class Benchmark_rep< CORE::BigInt > { 00182 const CORE::BigInt& t; 00183 public: 00185 Benchmark_rep( const CORE::BigInt& tt) : t(tt) {} 00187 std::ostream& operator()( std::ostream& out) const { 00188 out << t; 00189 return out; 00190 } 00191 00192 static std::string get_benchmark_name() { 00193 return "Integer"; 00194 } 00195 }; 00196 00197 00198 CGAL_END_NAMESPACE 00199 00200 //since types are included by CORE_coercion_traits.h: 00201 #include <CGAL/CORE_Expr.h> 00202 #include <CGAL/CORE_BigInt.h> 00203 #include <CGAL/CORE_BigRat.h> 00204 #include <CGAL/CORE_BigFloat.h> 00205 00206 #endif // CGAL_CORE_BIGINT_H
1.7.6.1