BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/leda_coercion_traits.h
Go to the documentation of this file.
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/leda_coercion_traits.h $
00016 // $Id: leda_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 
00026 #ifndef CGAL_LEDA_COERCION_TRAITS_H
00027 #define CGAL_LEDA_COERCION_TRAITS_H
00028 
00029 #include <CGAL/number_type_basic.h>
00030 
00031 #ifdef CGAL_USE_LEDA
00032 
00033 #include <CGAL/LEDA_basic.h>
00034 #if CGAL_LEDA_VERSION < 500
00035 #include <LEDA/integer.h>
00036 #include <LEDA/bigfloat.h>
00037 #include <LEDA/rational.h>
00038 #include <LEDA/real.h>
00039 #else
00040 #include <LEDA/numbers/integer.h>
00041 #include <LEDA/numbers/bigfloat.h>
00042 #include <LEDA/numbers/rational.h>
00043 #include <LEDA/numbers/real.h>
00044 #endif
00045 
00046 CGAL_BEGIN_NAMESPACE
00047 
00048 
00049 //LEDA internal coercions:
00050 
00051     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::leda::integer,::leda::bigfloat)
00052     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::leda::integer,::leda::rational)
00053     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::leda::integer,::leda::real)
00054 
00055 // CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::leda::bigfloat,::leda::rational); see below
00056     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::leda::bigfloat,::leda::real)
00057 
00058     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::leda::rational,::leda::real)
00059 
00060 // The following definitions reflect the interaction of the LEDA number types
00061 // with the built in types,
00062 // leda integer:
00063     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short    ,::leda::integer)
00064     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int      ,::leda::integer)
00065     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long     ,::leda::integer)
00066 
00067 // leda rational:
00068     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short      ,::leda::rational)
00069     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int        ,::leda::rational)
00070     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long       ,::leda::rational)
00071 
00072     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float      ,::leda::rational)
00073     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double     ,::leda::rational)
00074     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long double,::leda::rational)
00075 
00076 // leda bigfloat:      :
00077     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short      ,::leda::bigfloat)
00078     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int        ,::leda::bigfloat)
00079     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long       ,::leda::bigfloat)
00080     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float      ,::leda::bigfloat)
00081     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double     ,::leda::bigfloat)
00082 
00083 // leda real:
00084     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short      ,::leda::real)
00085     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int        ,::leda::real)
00086     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float      ,::leda::real)
00087     CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double     ,::leda::real)
00088 
00089 
00090 //not provided by LEDA
00091 //Note that this is not symmetric to CORE
00092 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long long,::leda::integer);
00093 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long long,::leda::rational);
00094 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long long  ,::leda::bigfloat);
00095 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long double,::leda::bigfloat);
00096 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long       ,::leda::real);
00097 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long long  ,::leda::real);
00098 //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long double,::leda::real);
00099 
00100 
00101 template <>
00102 struct Coercion_traits< ::leda::bigfloat ,::leda::rational  >{
00103     typedef Tag_true  Are_explicit_interoperable;
00104     typedef Tag_false Are_implicit_interoperable;
00105     typedef ::leda::rational Type;
00106     struct Cast{
00107         typedef Type result_type;
00108         Type operator()(const ::leda::rational& x)  const { return x;}
00109         Type operator()(const ::leda::bigfloat& x) const {
00110 #if CGAL_LEDA_VERSION < 500
00111             ::leda::integer e = x.get_exponent();
00112             ::leda::integer s = x.get_significant();
00113             if(e<0) {
00114                 ::leda::bigfloat b_two_to_e = ::leda::ipow2(-e);
00115                 ::leda::integer two_to_e = ::leda::floor(b_two_to_e);
00116                 return ::leda::rational(s,two_to_e);
00117             }
00118             // e >= 0
00119             ::leda::bigfloat b_two_to_e = ::leda::ipow2(e);
00120             ::leda::integer two_to_e = ::leda::floor(b_two_to_e);
00121             return ::leda::rational(s * two_to_e);
00122 #else
00123             return x.to_rational();
00124 #endif
00125         }
00126     };
00127 };
00128 template <> struct Coercion_traits< ::leda::rational, ::leda::bigfloat >
00129     :public Coercion_traits< ::leda::bigfloat , ::leda::rational >{};
00130 
00131 
00132 CGAL_END_NAMESPACE
00133 #endif // CGAL_USE_LEDA
00134 #endif //CGAL_LEDA_COERCION_TRAITS_H
00135 //EOF
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines