Boost logo

Boost-Commit :

From: steven_at_[hidden]
Date: 2008-06-07 13:15:24


Author: steven_watanabe
Date: 2008-06-07 13:15:24 EDT (Sat, 07 Jun 2008)
New Revision: 46217
URL: http://svn.boost.org/trac/boost/changeset/46217

Log:
Remove compiler specific code from cmath. Disable functions which cannot be implemented easily using Boost.Math
Text files modified:
   trunk/boost/units/cmath.hpp | 29 ++++++-
   trunk/boost/units/detail/cmath_impl.hpp | 145 +++++++++++++++++++++++++++++++++++++++
   trunk/libs/units/test/test_cmath.cpp | 17 +++-
   3 files changed, 179 insertions(+), 12 deletions(-)

Modified: trunk/boost/units/cmath.hpp
==============================================================================
--- trunk/boost/units/cmath.hpp (original)
+++ trunk/boost/units/cmath.hpp 2008-06-07 13:15:24 EDT (Sat, 07 Jun 2008)
@@ -13,7 +13,9 @@
 
 #include <boost/version.hpp>
 
-#if (BOOST_VERSION <= 103500)
+// The trunk still has BOOST_VERSION == 103500
+//#if (BOOST_VERSION <= 103500)
+#if 0
     #include <boost/units/detail/cmath_boost_1_35.hpp>
 #else
 
@@ -21,9 +23,10 @@
 #include <cstdlib>
 
 #include <boost/math/special_functions/fpclassify.hpp>
-#include <boost/math/special_functions/sign.hpp>
 #include <boost/math/special_functions/hypot.hpp>
+#include <boost/math/special_functions/next.hpp>
 #include <boost/math/special_functions/round.hpp>
+#include <boost/math/special_functions/sign.hpp>
 
 #include <boost/units/dimensionless_quantity.hpp>
 #include <boost/units/pow.hpp>
@@ -220,6 +223,8 @@
     return quantity_type::from_value(fdim BOOST_PREVENT_MACRO_SUBSTITUTION (q1.value(),q2.value()));
 }
 
+#if 0
+
 template<class Unit1,class Unit2,class Unit3,class Y>
 inline
 typename add_typeof_helper<
@@ -242,6 +247,8 @@
     return quantity_type::from_value(fma BOOST_PREVENT_MACRO_SUBSTITUTION (q1.value(),q2.value(),q3.value()));
 }
 
+#endif
+
 template<class Unit,class Y>
 inline
 quantity<Unit,Y>
@@ -326,6 +333,8 @@
 // return quantity_type::from_value(llround BOOST_PREVENT_MACRO_SUBSTITUTION (q.value()));
 //}
 
+#if 0
+
 template<class Unit,class Y>
 inline
 quantity<Unit,Y>
@@ -338,30 +347,36 @@
     return quantity_type::from_value(nearbyint BOOST_PREVENT_MACRO_SUBSTITUTION (q.value()));
 }
 
+#endif
+
 template<class Unit,class Y>
 inline
 quantity<Unit,Y> nextafter BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q1,
                                                              const quantity<Unit,Y>& q2)
 {
- using namespace detail;
+ using boost::math::nextafter;
 
     typedef quantity<Unit,Y> quantity_type;
     
     return quantity_type::from_value(nextafter BOOST_PREVENT_MACRO_SUBSTITUTION (q1.value(),q2.value()));
 }
-
 template<class Unit,class Y>
 inline
 quantity<Unit,Y> nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q1,
                                                               const quantity<Unit,Y>& q2)
 {
- using namespace detail;
+ // the only difference between nextafter and nexttowards is
+ // in the argument types. Since we are requiring identical
+ // argument types, there is no difference.
+ using boost::math::nextafter;
 
     typedef quantity<Unit,Y> quantity_type;
     
- return quantity_type::from_value(nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION (q1.value(),q2.value()));
+ return quantity_type::from_value(nextafter BOOST_PREVENT_MACRO_SUBSTITUTION (q1.value(),q2.value()));
 }
 
+#if 0
+
 template<class Unit,class Y>
 inline
 quantity<Unit,Y>
@@ -374,6 +389,8 @@
     return quantity_type::from_value(rint BOOST_PREVENT_MACRO_SUBSTITUTION (q.value()));
 }
 
+#endif
+
 template<class Unit,class Y>
 inline
 quantity<Unit,Y>

Modified: trunk/boost/units/detail/cmath_impl.hpp
==============================================================================
--- trunk/boost/units/detail/cmath_impl.hpp (original)
+++ trunk/boost/units/detail/cmath_impl.hpp 2008-06-07 13:15:24 EDT (Sat, 07 Jun 2008)
@@ -13,14 +13,157 @@
 
 #include <boost/version.hpp>
 
-#if (BOOST_VERSION <= 103500)
+#if 0
+//#if (BOOST_VERSION <= 103500)
     #include <boost/units/detail/cmath_gnu_impl_boost_1_35.hpp>
     #include <boost/units/detail/cmath_mwcw_impl_boost_1_35.hpp>
     #include <boost/units/detail/cmath_msvc_impl_boost_1_35.hpp>
 #else
+#if 0
     #include <boost/units/detail/cmath_gnu_impl.hpp>
     #include <boost/units/detail/cmath_mwcw_impl.hpp>
     #include <boost/units/detail/cmath_msvc_impl.hpp>
+# endif
+
+#include <boost/math/special_functions/fpclassify.hpp>
+
+namespace boost {
+namespace units {
+namespace detail {
+
+template<class Y>
+inline bool isgreater(const Y& v1,const Y& v2)
+{
+ if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
+ else return v1 > v2;
+}
+
+template<class Y>
+inline bool isgreaterequal(const Y& v1,const Y& v2)
+{
+ if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
+ else return v1 >= v2;
+}
+
+template<class Y>
+inline bool isless(const Y& v1,const Y& v2)
+{
+ if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
+ else return v1 < v2;
+}
+
+template<class Y>
+inline bool islessequal(const Y& v1,const Y& v2)
+{
+ if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
+ else return v1 <= v2;
+}
+
+template<class Y>
+inline bool islessgreater(const Y& v1,const Y& v2)
+{
+ if((boost::math::isnan)(v1) || (boost::math::isnan)(v2)) return false;
+ else return v1 < v2 || v1 > v2;
+}
+
+template<class Y>
+inline bool isunordered(const Y& v1,const Y& v2)
+{
+ return (boost::math::isnan)(v1) || (boost::math::isnan)(v2);
+}
+
+template<class Y>
+inline Y fdim(const Y& v1,const Y& v2)
+{
+ if((boost::math::isnan)(v1)) return v1;
+ else if((boost::math::isnan)(v2)) return v2;
+ else if(v1 > v2) return(v1 - v2);
+ else return(Y(0));
+}
+
+#if 0
+
+template<class T>
+struct fma_issue_warning {
+ enum { value = false };
+};
+
+template<class Y>
+inline Y fma(const Y& v1,const Y& v2,const Y& v3)
+{
+ //this implementation does *not* meet the
+ //requirement of infinite intermediate precision
+ BOOST_STATIC_WARNING((fma_issue_warning<Y>::value));
+
+ return v1 * v2 + v3;
+}
+
+#endif
+
+template<class Y>
+inline Y fmax(const Y& v1,const Y& v2)
+{
+ if((boost::math::isnan)(v1)) return(v2);
+ else if((boost::math::isnan)(v2)) return(v1);
+ else if(v1 > v2) return(v1);
+ else return(v2);
+}
+
+template<class Y>
+inline Y fmin(const Y& v1,const Y& v2)
+{
+ if((boost::math::isnan)(v1)) return(v2);
+ else if((boost::math::isnan)(v2)) return(v1);
+ else if(v1 < v2) return(v1);
+ else return(v2);
+}
+
+//template<class Y>
+//inline long long llrint(const Y& val)
+//{
+// return static_cast<long long>(rint(val));
+//}
+//
+//template<class Y>
+//inline long long llround(const Y& val)
+//{
+// return static_cast<long long>(round(val));
+//}
+
+#if 0
+
+template<class Y>
+inline Y nearbyint(const Y& val)
+{
+ //this is not really correct.
+ //the result should be according to the
+ //current rounding mode.
+ using boost::math::round;
+ return round(val);
+}
+
+template<class Y>
+inline Y rint(const Y& val)
+{
+ //I don't feel like trying to figure out
+ //how to raise a floating pointer exception
+ return nearbyint(val);
+}
+
+#endif
+
+template<class Y>
+inline Y trunc(const Y& val)
+{
+ if(val > 0) return std::floor(val);
+ else if(val < 0) return std::ceil(val);
+ else return val;
+}
+
+}
+}
+}
+
 #endif // (BOOST_VERSION <= 103500)
 
 #endif // BOOST_UNITS_CMATH_IMPL_HPP

Modified: trunk/libs/units/test/test_cmath.cpp
==============================================================================
--- trunk/libs/units/test/test_cmath.cpp (original)
+++ trunk/libs/units/test/test_cmath.cpp 2008-06-07 13:15:24 EDT (Sat, 07 Jun 2008)
@@ -108,8 +108,10 @@
                                     L2(4.0*bu::meters);
     const bu::quantity<bu::area> A1(4.0*bu::square_meters),
                                     A2(L1*L2+A1);
-
+
+#if 0
     BOOST_CHECK((bu::fma)(L1,L2,A1) == A2);
+#endif
        
     BOOST_CHECK((bu::fmax)(E4,E5) == E5);
     BOOST_CHECK((bu::fmin)(E4,E5) == E4);
@@ -118,15 +120,20 @@
     
     BOOST_CHECK(bu::hypot(L1,L2) == 5.0*bu::meters);
     
+#if 0
+
 // BOOST_CHECK(bu::llrint(E4).value() == bu::detail::llrint(E4.value()));
 // BOOST_CHECK(bu::llround(E4).value() == bu::detail::llround(E4.value()));
     BOOST_CHECK((bu::nearbyint)(E4).value() == (bu::detail::nearbyint)(E4.value()));
     BOOST_CHECK((bu::rint)(E4).value() == (bu::detail::rint)(E4.value()));
 
- BOOST_CHECK((bu::nextafter)(E4,E5).value() == (bu::detail::nextafter)(E4.value(),E5.value()));
- BOOST_CHECK((bu::nextafter)(E5,E4).value() == (bu::detail::nextafter)(E5.value(),E4.value()));
- BOOST_CHECK((bu::nexttoward)(E4,E5).value() == (bu::detail::nexttoward)(E4.value(),E5.value()));
- BOOST_CHECK((bu::nexttoward)(E5,E4).value() == (bu::detail::nexttoward)(E5.value(),E4.value()));
+#endif
+
+ BOOST_CHECK((bu::nextafter)(E4,E5).value() == (boost::math::nextafter)(E4.value(),E5.value()));
+ BOOST_CHECK((bu::nextafter)(E5,E4).value() == (boost::math::nextafter)(E5.value(),E4.value()));
+
+ BOOST_CHECK((bu::nexttoward)(E4,E5).value() == (boost::math::nextafter)(E4.value(),E5.value()));
+ BOOST_CHECK((bu::nexttoward)(E5,E4).value() == (boost::math::nextafter)(E5.value(),E4.value()));
 
     BOOST_CHECK((bu::round)(E4 - 0.00000000001 * bu::joules) == -3.0*bu::joules);
     BOOST_CHECK((bu::round)(E5 + 0.00000000001 * bu::joules) == 3.0*bu::joules);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk