BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Static_filters/tools.h
Go to the documentation of this file.
00001 // Copyright (c) 2001,2004  INRIA Sophia-Antipolis (France).
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/Filtered_kernel/include/CGAL/Static_filters/tools.h $
00016 // $Id: tools.h 35070 2006-11-06 17:12:11Z spion $
00017 // 
00018 //
00019 // Author(s)     : Sylvain Pion
00020  
00021 #ifndef CGAL_STATIC_FILTERS_TOOLS_H
00022 #define CGAL_STATIC_FILTERS_TOOLS_H
00023 
00024 #include <CGAL/basic.h>
00025 
00026 CGAL_BEGIN_NAMESPACE
00027 
00028 // Utility function to check a posteriori that a subtraction was performed
00029 // without rounding error.
00030 inline bool diff_was_exact(double a, double b, double ab)
00031 {
00032     return ab+b == a && a-ab == b;
00033 }
00034 
00035 // Auxiliary function to check if static filters can be applied, that is,
00036 // if to_double() does not add roundoff errors.
00037 // TODO :
00038 // - generalize it to other number types.
00039 // - promote it as a number type requirement ?
00040 // - naming : is_representable_in_double() ?
00041 //            is_representable<T>() for representable in T ?
00042 
00043 // Current semantics :  bool fit_in_double(const NT& n, double &)
00044 //
00045 // - returns true means that "n" is exactly representable by a double,
00046 //   _and_ then "returns" it in the reference.
00047 // - it is fine to return false conservatively.
00048 
00049 template < typename T >
00050 inline bool fit_in_double(const T&, double&) { return false; }
00051 
00052 inline bool fit_in_double(const double& d, double& r) { r = d; return true; }
00053 
00054 inline bool fit_in_double(const float& f, double& r) { r = f; return true; }
00055 
00056 inline bool fit_in_double(const int& i, double& r) { r = i; return true; }
00057 
00058 template < typename ET >
00059 class Lazy_exact_nt;
00060 
00061 template < typename ET >
00062 inline bool fit_in_double(const Lazy_exact_nt<ET>&, double&);
00063 
00064 CGAL_END_NAMESPACE
00065 
00066 #endif // CGAL_STATIC_FILTERS_TOOLS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines