BWAPI
|
00001 // Copyright (c) 1999,2007 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/Number_types/include/CGAL/float.h $ 00019 // $Id: float.h 44911 2008-08-12 13:09:51Z spion $ 00020 // 00021 // 00022 // Author(s) : Geert-Jan Giezeman, Michael Hemmer 00023 00024 00025 #ifndef CGAL_FLOAT_H 00026 #define CGAL_FLOAT_H 00027 00028 #include <CGAL/number_type_basic.h> 00029 00030 #include <cmath> // std::sqrt, std::pow 00031 00032 #ifdef CGAL_CFG_IEEE_754_BUG 00033 # include <CGAL/IEEE_754_unions.h> 00034 #endif 00035 00036 CGAL_BEGIN_NAMESPACE 00037 00038 #ifdef CGAL_CFG_IEEE_754_BUG 00039 00040 #define CGAL_EXPONENT_FLOAT_MASK 0x7f800000 00041 #define CGAL_MANTISSA_FLOAT_MASK 0x007fffff 00042 00043 inline 00044 bool 00045 is_finite_by_mask_float(unsigned int u) 00046 { 00047 unsigned int e = u & CGAL_EXPONENT_FLOAT_MASK; 00048 return ( (e ^ CGAL_EXPONENT_FLOAT_MASK) != 0); 00049 } 00050 00051 inline 00052 bool 00053 is_nan_by_mask_float(unsigned int u) 00054 { 00055 if ( is_finite_by_mask_float(u) ) return false; 00056 // unsigned int m = u & CGAL_MANTISSA_FLOAT_MASK; 00057 return ( (u & CGAL_MANTISSA_FLOAT_MASK) != 0); 00058 } 00059 00060 template<> 00061 class Is_valid< float > 00062 : public std::unary_function< float, bool > { 00063 public : 00064 bool operator()( const float& x ) const { 00065 float f = x; 00066 IEEE_754_float* p = reinterpret_cast<IEEE_754_float*>(&f); 00067 return !is_nan_by_mask_float( p->c ); 00068 } 00069 }; 00070 00071 #else 00072 00073 template<> 00074 class Is_valid< float > 00075 : public std::unary_function< float, bool > { 00076 public : 00077 bool operator()( const float& x ) const { 00078 return (x == x); 00079 } 00080 }; 00081 00082 #endif 00083 00084 template <> class Algebraic_structure_traits< float > 00085 : public Algebraic_structure_traits_base< float, 00086 Field_with_kth_root_tag > { 00087 public: 00088 typedef Tag_false Is_exact; 00089 typedef Tag_true Is_numerical_sensitive; 00090 00091 class Sqrt 00092 : public std::unary_function< Type, Type > { 00093 public: 00094 Type operator()( const Type& x ) const { 00095 return std::sqrt( x ); 00096 } 00097 }; 00098 00099 class Kth_root 00100 : public std::binary_function<int, Type, Type> { 00101 public: 00102 Type operator()( int k, const Type& x) const { 00103 CGAL_precondition_msg( k > 0, "'k' must be positive for k-th roots"); 00104 return (Type) std::pow(double(x), 1.0 / double(k)); 00105 }; 00106 }; 00107 00108 }; 00109 00110 template <> class Real_embeddable_traits< float > 00111 : public INTERN_RET::Real_embeddable_traits_base< float , CGAL::Tag_true> { 00112 public: 00113 // Is_finite depends on platform 00114 class Is_finite 00115 : public std::unary_function< Type, bool > { 00116 public: 00117 bool operator()( const Type& x ) const { 00118 #ifdef CGAL_CFG_IEEE_754_BUG 00119 Type f = x; 00120 IEEE_754_float* p = reinterpret_cast<IEEE_754_float*>(&f); 00121 return is_finite_by_mask_float( p->c ); 00122 #else 00123 return (x == x) && (is_valid(x-x)); 00124 #endif 00125 } 00126 }; 00127 00128 }; 00129 00130 CGAL_END_NAMESPACE 00131 00132 #endif // CGAL_FLOAT_H