|
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_coercion_traits.h $ 00016 // $Id: CORE_coercion_traits.h 47264 2008-12-08 06:25:14Z hemmer $ 00017 // 00018 // 00019 // Author(s) : Michael Hemmer <hemmer@mpi-inf.mpg.de> 00020 00021 00022 #ifndef CGAL_CORE_COERCION_TRAITS_H 00023 #define CGAL_CORE_COERCION_TRAITS_H 1 00024 00025 #include <CGAL/number_type_basic.h> 00026 00027 #ifdef CGAL_USE_CORE 00028 00029 #ifndef CORE_LEVEL 00030 #define CORE_LEVEL 4 00031 #endif 00032 00033 #include <CGAL/CORE/CORE.h> 00034 00035 //#include <NiX/Coercion_traits.h> 00036 00037 CGAL_BEGIN_NAMESPACE 00038 00039 //CORE internal coercions: 00040 00041 00042 // The following definitions reflect the interaction of the CORE number types 00043 // with the built in types, 00044 // CORE BigInt: 00045 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::BigInt) 00046 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::BigInt) 00047 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::BigInt) 00048 00049 00050 // CORE BigRat: 00051 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::BigRat) 00052 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::BigRat) 00053 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::BigRat) 00054 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::BigRat) 00055 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::BigRat) 00056 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigInt,::CORE::BigRat) 00057 00058 // CORE Expr: 00059 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::Expr) 00060 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::Expr) 00061 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::Expr) 00062 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::Expr) 00063 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::Expr) 00064 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigInt,::CORE::Expr) 00065 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigRat,::CORE::Expr) 00066 00067 00068 00069 // NOTE that CORE::BigFloat counts as an interval ! 00070 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::BigFloat) 00071 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::BigFloat) 00072 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::BigFloat) 00073 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::BigFloat) 00074 CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::BigFloat); 00075 00076 template <> 00077 struct Coercion_traits<CORE::BigFloat , ::CORE::BigInt>{ 00078 typedef Tag_true Are_explicit_interoperable; 00079 typedef Tag_false Are_implicit_interoperable; 00080 typedef CORE::BigFloat Type; 00081 00082 struct Cast{ 00083 typedef Type result_type; 00084 Type operator()(const CORE::BigFloat& x) const { return x;} 00085 Type operator()(const ::CORE::BigInt x) const { 00086 CORE::BigFloat result; 00087 result.approx(x,CORE::defRelPrec.toLong(),LONG_MAX); 00088 // Do not use MakeFloorExact as it changes the Bigfloat 00089 CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()-result.err(),0,result.exp())) <= x ); 00090 CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()+result.err(),0,result.exp())) >= x ); 00091 return result; 00092 } 00093 }; 00094 }; 00095 00096 template <> 00097 struct Coercion_traits<CORE::BigFloat , ::CORE::BigRat>{ 00098 typedef Tag_true Are_explicit_interoperable; 00099 typedef Tag_false Are_implicit_interoperable; 00100 typedef CORE::BigFloat Type; 00101 00102 struct Cast{ 00103 typedef Type result_type; 00104 Type operator()(const CORE::BigFloat& x) const { return x;} 00105 Type operator()(const ::CORE::BigRat x) const { 00106 00107 CORE::BigFloat result(x,CORE::defRelPrec.toLong(),LONG_MAX); 00108 // Do not use MakeFloorExact as it changes the Bigfloat 00109 CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()-result.err(),0,result.exp())) <= x ); 00110 CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()+result.err(),0,result.exp())) >= x ); 00111 return result; 00112 } 00113 }; 00114 }; 00115 00116 template <> 00117 struct Coercion_traits<CORE::BigFloat , ::CORE::Expr>{ 00118 typedef Tag_true Are_explicit_interoperable; 00119 typedef Tag_false Are_implicit_interoperable; 00120 typedef CORE::BigFloat Type; 00121 00122 struct Cast{ 00123 typedef Type result_type; 00124 Type operator()(const CORE::BigFloat& x) const { return x;} 00125 Type operator()(const ::CORE::Expr x) const { 00126 CORE::BigFloat result(x, CORE::defRelPrec.toLong(),LONG_MAX); 00127 // Do not use MakeFloorExact as it changes the Bigfloat 00128 CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()-result.err(),0,result.exp())) <= x ); 00129 CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()+result.err(),0,result.exp())) >= x ); 00130 return result; 00131 } 00132 }; 00133 }; 00134 00135 template <> struct Coercion_traits< ::CORE::BigInt, CORE::BigFloat > 00136 :public Coercion_traits< CORE::BigFloat , ::CORE::BigInt >{}; 00137 00138 template <> struct Coercion_traits< ::CORE::BigRat, CORE::BigFloat > 00139 :public Coercion_traits< CORE::BigFloat , ::CORE::BigRat >{}; 00140 00141 template <> struct Coercion_traits< ::CORE::Expr, CORE::BigFloat > 00142 :public Coercion_traits< CORE::BigFloat , ::CORE::Expr>{}; 00143 00144 00145 00146 00147 00148 00149 // not provieded by CORE 00150 // Note that this is not symmetric to LEDA 00151 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long long ,::CORE::BigInt) 00152 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long long ,::CORE::BigRat) 00153 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long double,::CORE::BigRat) 00154 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long long ,::CORE::BigFloat) 00155 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long double,::CORE::BigFloat) 00156 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long long ,::CORE::Expr) 00157 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long double,::CORE::Expr) 00158 00159 CGAL_END_NAMESPACE 00160 00161 #endif // CGAL_USE_CORE 00162 #endif //CGAL_CORE_COERCION_TRAITS_H 1 00163 //EOF
1.7.6.1