BWAPI
|
00001 // Copyright (c) 2006-2008 Fernando Luis Cacciola Carballal. All rights reserved. 00002 // 00003 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00004 // modify it under the terms of the GNU Lesser General Public License as 00005 // published by the Free Software Foundation; version 2.1 of the License. 00006 // See the file LICENSE.LGPL distributed with CGAL. 00007 // 00008 // Licensees holding a valid commercial license may use this file in 00009 // accordance with the commercial license agreement provided with the software. 00010 // 00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 // 00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Straight_skeleton_2/include/CGAL/certified_quotient_predicates.h $ 00015 // $Id: certified_quotient_predicates.h 44901 2008-08-12 09:04:37Z spion $ 00016 // 00017 // Author(s) : Fernando Cacciola <fernando_cacciola@ciudad.com.ar> 00018 // 00019 #ifndef CGAL_CERTIFIED_QUOTIENT_PREDICATES_H 00020 #define CGAL_CERTIFIED_QUOTIENT_PREDICATES_H 00021 00022 #include <CGAL/certified_numeric_predicates.h> 00023 #include <CGAL/Quotient.h> 00024 00025 CGAL_BEGIN_NAMESPACE 00026 00027 template <class NT> 00028 inline Uncertain<bool> certified_quotient_is_positive(const Quotient<NT>& x) 00029 { 00030 Uncertain<Sign> signum = CGAL_NTS certified_sign(x.num) ; 00031 Uncertain<Sign> sigden = CGAL_NTS certified_sign(x.den) ; 00032 Uncertain<Sign> zero(ZERO); 00033 return ( signum != zero ) & ( signum == sigden ); 00034 } 00035 00036 template <class NT> 00037 inline Uncertain<bool> certified_quotient_is_negative(const Quotient<NT>& x) 00038 { 00039 Uncertain<Sign> signum = CGAL_NTS certified_sign(x.num) ; 00040 Uncertain<Sign> sigden = CGAL_NTS certified_sign(x.den) ; 00041 Uncertain<Sign> zero(ZERO); 00042 00043 return ( signum != zero ) & ( signum != sigden ); 00044 } 00045 00046 template <class NT> 00047 inline Uncertain<bool> certified_quotient_is_zero(const Quotient<NT>& x) 00048 { 00049 return CGAL_NTS certified_is_zero(x.num) ; 00050 } 00051 00052 template <class NT> 00053 CGAL_MEDIUM_INLINE 00054 Uncertain<Sign> certified_quotient_sign(const Quotient<NT>& x) 00055 { 00056 // No assumptions on the sign of den are made 00057 00058 return CGAL_NTS certified_sign(x.num) * CGAL_NTS certified_sign(x.den); 00059 } 00060 00061 template <class NT1, class NT2> 00062 CGAL_MEDIUM_INLINE 00063 Uncertain<Comparison_result> certified_quotient_compare(const Quotient<NT1>& x, const Quotient<NT2>& y) 00064 { 00065 Uncertain<Comparison_result> r = Uncertain<Comparison_result>::indeterminate(); 00066 00067 // No assumptions on the sign of den are made 00068 00069 // code assumes that SMALLER == - 1; 00070 CGAL_precondition( SMALLER == static_cast<Comparison_result>(-1) ); 00071 00072 Uncertain<Sign> xnumsign = CGAL_NTS certified_sign(x.num) ; 00073 Uncertain<Sign> xdensign = CGAL_NTS certified_sign(x.den) ; 00074 Uncertain<Sign> ynumsign = CGAL_NTS certified_sign(y.num) ; 00075 Uncertain<Sign> ydensign = CGAL_NTS certified_sign(y.den) ; 00076 00077 if ( is_certain(xnumsign) 00078 && is_certain(xdensign) 00079 && is_certain(ynumsign) 00080 && is_certain(ydensign) 00081 ) 00082 { 00083 int xsign = xnumsign * xdensign ; 00084 int ysign = ynumsign * ydensign ; 00085 if (xsign == 0) return static_cast<Comparison_result>(-ysign); 00086 if (ysign == 0) return static_cast<Comparison_result>(xsign); 00087 // now (x != 0) && (y != 0) 00088 int diff = xsign - ysign; 00089 if (diff == 0) 00090 { 00091 int msign = xdensign * ydensign; 00092 NT1 leftop = x.num * y.den * msign; 00093 NT1 rightop = y.num * x.den * msign; 00094 r = certified_compare(leftop, rightop); 00095 } 00096 else 00097 { 00098 r = (xsign < ysign) ? SMALLER : LARGER; 00099 } 00100 } 00101 00102 return r ; 00103 } 00104 00105 template <class NT> 00106 inline Uncertain<bool> certified_is_zero(const Quotient<NT>& n) 00107 { 00108 return certified_quotient_is_zero(n); 00109 } 00110 template <class NT> 00111 inline Uncertain<bool> certified_is_positive(const Quotient<NT>& n) 00112 { 00113 return certified_quotient_is_positive(n); 00114 } 00115 template <class NT> 00116 inline Uncertain<bool> certified_is_negative(const Quotient<NT>& n) 00117 { 00118 return certified_quotient_is_negative(n); 00119 } 00120 template <class NT> 00121 inline Uncertain<Sign> certified_sign(const Quotient<NT>& n) 00122 { 00123 return certified_quotient_sign(n); 00124 } 00125 00126 template <class NT1, class NT2> 00127 inline Uncertain<Comparison_result> certified_compare(const Quotient<NT1>& n1, const Quotient<NT2>& n2) 00128 { 00129 return certified_quotient_compare(n1,n2); 00130 } 00131 00132 CGAL_END_NAMESPACE 00133 00134 #endif // CGAL_CERTIFIED_QUOTIENT_PREDICATES_H 00135