|
Boost-Commit : |
From: steven_at_[hidden]
Date: 2008-05-13 17:08:38
Author: steven_watanabe
Date: 2008-05-13 17:08:38 EDT (Tue, 13 May 2008)
New Revision: 45342
URL: http://svn.boost.org/trac/boost/changeset/45342
Log:
Use Boost.Math or std functions where appropriate
Text files modified:
sandbox/units/boost/units/cmath.hpp | 33 ++++--
sandbox/units/boost/units/detail/cmath_gnu_impl.hpp | 72 ---------------
sandbox/units/boost/units/detail/cmath_msvc_impl.hpp | 189 +--------------------------------------
sandbox/units/boost/units/detail/cmath_mwcw_impl.hpp | 78 ----------------
sandbox/units/libs/units/test/test_cmath.cpp | 8
5 files changed, 28 insertions(+), 352 deletions(-)
Modified: sandbox/units/boost/units/cmath.hpp
==============================================================================
--- sandbox/units/boost/units/cmath.hpp (original)
+++ sandbox/units/boost/units/cmath.hpp 2008-05-13 17:08:38 EDT (Tue, 13 May 2008)
@@ -12,9 +12,14 @@
#define BOOST_UNITS_CMATH_HPP
#include <cmath>
+#include <cstdlib>
#include <boost/units/quantity.hpp>
#include <boost/units/detail/cmath_impl.hpp>
+#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/round.hpp>
/// \file
/// \brief Overloads of functions in \<cmath\> for quantities
@@ -39,7 +44,7 @@
bool
isfinite BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q)
{
- using namespace detail;
+ using boost::math::isfinite;
return isfinite BOOST_PREVENT_MACRO_SUBSTITUTION (q.value());
}
@@ -48,7 +53,7 @@
bool
isinf BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q)
{
- using namespace detail;
+ using boost::math::isinf;
return isinf BOOST_PREVENT_MACRO_SUBSTITUTION (q.value());
}
@@ -57,7 +62,7 @@
bool
isnan BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q)
{
- using namespace detail;
+ using boost::math::isnan;
return isnan BOOST_PREVENT_MACRO_SUBSTITUTION (q.value());
}
@@ -66,7 +71,7 @@
bool
isnormal BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q)
{
- using namespace detail;
+ using boost::math::isnormal;
return isnormal BOOST_PREVENT_MACRO_SUBSTITUTION (q.value());
}
@@ -135,7 +140,7 @@
quantity<Unit,Y>
abs BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q)
{
- using namespace detail;
+ using std::abs;
typedef quantity<Unit,Y> quantity_type;
@@ -147,7 +152,7 @@
quantity<Unit,Y>
ceil BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q)
{
- using namespace detail;
+ using std::ceil;
typedef quantity<Unit,Y> quantity_type;
@@ -160,7 +165,7 @@
copysign BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q1,
const quantity<Unit,Y>& q2)
{
- using namespace detail;
+ using boost::math::copysign;
typedef quantity<Unit,Y> quantity_type;
@@ -172,7 +177,7 @@
quantity<Unit,Y>
fabs BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q)
{
- using namespace detail;
+ using std::fabs;
typedef quantity<Unit,Y> quantity_type;
@@ -184,7 +189,7 @@
quantity<Unit,Y>
floor BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q)
{
- using namespace detail;
+ using std::floor;
typedef quantity<Unit,Y> quantity_type;
@@ -257,7 +262,7 @@
int
fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q)
{
- using namespace detail;
+ using boost::math::fpclassify;
return fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION (q.value());
}
@@ -273,7 +278,7 @@
static_rational<2> >::type
hypot BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q1,const quantity<Unit,Y>& q2)
{
- using namespace detail;
+ using boost::math::hypot;
typedef quantity<Unit,Y> type1;
@@ -363,7 +368,7 @@
quantity<Unit,Y>
round BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q)
{
- using namespace detail;
+ using boost::math::round;
typedef quantity<Unit,Y> quantity_type;
@@ -372,10 +377,10 @@
template<class Unit,class Y>
inline
-bool
+int
signbit BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q)
{
- using namespace detail;
+ using boost::math::signbit;
return signbit BOOST_PREVENT_MACRO_SUBSTITUTION (q.value());
}
Modified: sandbox/units/boost/units/detail/cmath_gnu_impl.hpp
==============================================================================
--- sandbox/units/boost/units/detail/cmath_gnu_impl.hpp (original)
+++ sandbox/units/boost/units/detail/cmath_gnu_impl.hpp 2008-05-13 17:08:38 EDT (Tue, 13 May 2008)
@@ -22,30 +22,6 @@
namespace detail {
template<class Y>
-inline bool isfinite(const Y& val)
-{
- return std::isfinite(val);
-}
-
-template<class Y>
-inline bool isinf(const Y& val)
-{
- return std::isinf(val);
-}
-
-template<class Y>
-inline bool isnan(const Y& val)
-{
- return std::isnan(val);
-}
-
-template<class Y>
-inline bool isnormal(const Y& val)
-{
- return std::isnormal(val);
-}
-
-template<class Y>
inline bool isgreater(const Y& v1,const Y& v2)
{
return __builtin_isgreater(v1,v2);
@@ -82,36 +58,6 @@
}
template<class Y>
-inline Y abs(const Y& val)
-{
- return std::abs(val);
-}
-
-template<class Y>
-inline Y ceil(const Y& val)
-{
- return __builtin_ceil(val);
-}
-
-template<class Y>
-inline Y copysign(const Y& v1,const Y& v2)
-{
- return __builtin_copysign(v1,v2);
-}
-
-template<class Y>
-inline Y fabs(const Y& val)
-{
- return __builtin_fabs(val);
-}
-
-template<class Y>
-inline Y floor(const Y& val)
-{
- return __builtin_floor(val);
-}
-
-template<class Y>
inline Y fdim(const Y& v1,const Y& v2)
{
return __builtin_fdim(v1,v2);
@@ -135,18 +81,6 @@
return __builtin_fmin(v1,v2);
}
-template<class Y>
-inline int fpclassify(const Y& val)
-{
- return std::fpclassify(val);
-}
-
-template<class Y>
-inline Y hypot(const Y& v1,const Y& v2)
-{
- return __builtin_hypot(v1,v2);
-}
-
//template<class Y>
//inline long long llrint(const Y& val)
//{
@@ -184,12 +118,6 @@
}
template<class Y>
-inline Y round(const Y& val)
-{
- return __builtin_round(val);
-}
-
-template<class Y>
inline bool signbit(const Y& val)
{
return __builtin_signbit(val);
Modified: sandbox/units/boost/units/detail/cmath_msvc_impl.hpp
==============================================================================
--- sandbox/units/boost/units/detail/cmath_msvc_impl.hpp (original)
+++ sandbox/units/boost/units/detail/cmath_msvc_impl.hpp 2008-05-13 17:08:38 EDT (Tue, 13 May 2008)
@@ -19,7 +19,8 @@
#include <cmath>
#include <boost/static_warning.hpp>
-#include <boost/mpl/bool.hpp>
+#include <boost/math/special_functions/round.hpp>
+#include <boost/math/special_functions/fpclassify.hpp>
namespace boost {
@@ -28,31 +29,6 @@
namespace detail {
template<class Y>
-inline bool isfinite(const Y& val)
-{
- return _finite(val) != 0;
-}
-
-template<class Y>
-inline bool isinf(const Y& val)
-{
- return !isfinite(val) && !isnan(val);
-}
-
-template<class Y>
-inline bool isnan(const Y& val)
-{
- return _isnan(val) != 0;
-}
-
-template<class Y>
-inline bool isnormal(const Y& val)
-{
- int class_ = _fpclass(val);
- return class_ == _FPCLASS_NN || class_ == _FPCLASS_PN;
-}
-
-template<class Y>
inline bool isgreater(const Y& v1,const Y& v2)
{
if(_fpclass(v1) == _FPCLASS_SNAN || _fpclass(v2) == _FPCLASS_SNAN) return false;
@@ -90,51 +66,14 @@
template<class Y>
inline bool isunordered(const Y& v1,const Y& v2)
{
+ using boost::math::isnan;
return isnan(v1) || isnan(v2);
}
template<class Y>
-inline Y abs(const Y& val)
-{
- return ::abs(val);
-}
-
-template<class Y>
-inline Y ceil(const Y& val)
-{
- return ::ceil(val);
-}
-
-template<class Y>
-inline Y copysign(const Y& v1,const Y& v2)
-{
- return ::_copysign(v1,v2);
-}
-
-#if _MSC_VER == 1400
-// unavailable on MSVC 7.1
-template<>
-inline long double copysign(const long double& v1,const long double& v2)
-{
- return ::_copysignl(v1,v2);
-}
-#endif
-
-template<class Y>
-inline Y fabs(const Y& val)
-{
- return ::fabs(val);
-}
-
-template<class Y>
-inline Y floor(const Y& val)
-{
- return ::floor(val);
-}
-
-template<class Y>
inline Y fdim(const Y& v1,const Y& v2)
{
+ using boost::math::isnan;
if(isnan(v1)) return v1;
else if(isnan(v2)) return v2;
else if(v1 > v2) return(v1 - v2);
@@ -168,73 +107,6 @@
return __min(v1,v2);
}
-template<class Y>
-inline int fpclassify(const Y& val)
-{
- return ::_fpclass(val);
-}
-
-template<class Y>
-inline Y hypot(const Y& v1,const Y& v2)
-{
- return ::_hypot(v1,v2);
-}
-
-namespace hypotf_impl {
-
-struct convertible_from_float
-{
- convertible_from_float(const float&) {}
-};
-
-typedef char no;
-
-struct yes { no dummy[2]; };
-
-struct hypot_result {};
-
-hypot_result hypotf(const convertible_from_float&, const convertible_from_float&);
-hypot_result _hypotf(const convertible_from_float&, const convertible_from_float&);
-
-no has_hypot(hypot_result);
-
-yes has_hypot(float);
-
-template<class Float>
-inline float do_hypot_(const Float& v1,const Float& v2, mpl::true_)
-{
- return ::_hypotf(v1,v2);
-}
-
-template<class Float>
-inline float do_hypot_(const Float& v1,const Float& v2, mpl::false_)
-{
- return static_cast<float>(::_hypot(v1,v2));
-}
-
-template<class Float>
-inline float do_hypot(const Float& v1,const Float& v2, mpl::true_)
-{
- return ::_hypotf(v1,v2);
-}
-
-template<class Float>
-inline float do_hypot(const Float& v1,const Float& v2, mpl::false_)
-{
- mpl::bool_<(sizeof(hypotf_impl::has_hypot(_hypotf(v1, v2)))==sizeof(hypotf_impl::yes))> condition;
- return hypotf_impl::do_hypot_(v1,v2, condition);
-}
-
-}
-
-template<>
-inline float hypot(const float& v1,const float& v2)
-{
- using namespace hypotf_impl;
- mpl::bool_<(sizeof(hypotf_impl::has_hypot(hypotf(v1, v2)))==sizeof(hypotf_impl::yes))> condition;
- return hypotf_impl::do_hypot(v1,v2,condition);
-}
-
//template<class Y>
//inline long long llrint(const Y& val)
//{
@@ -253,6 +125,7 @@
//this is not really correct.
//the result should be according to the
//current rounding mode.
+ using boost::math::round;
return round(val);
}
@@ -279,58 +152,6 @@
}
template<class Y>
-inline Y round(const Y& val)
-{
- if(isnan(val)) return val;
- if(val == 0) return val;
- if(val > 0)
- {
- Y result1(val + .5);
- if(result1 != std::numeric_limits<Y>::infinity()) return std::floor(result1);
- Y result2(val - .5);
- Y result3(std::ceil(result2));
- if(result3 == result2)
- if(result3 == val) return val;
- else return std::ceil(val);
- else return result3;
- }
- else
- {
- Y result1(val - .5);
- if(result1 != -std::numeric_limits<Y>::infinity()) return std::ceil(result1);
- Y result2(val + .5);
- Y result3(std::floor(result2));
- if(result3 == result2)
- if(result3 == val) return val;
- else return std::floor(val);
- else return result3;
- }
-}
-
-template<class Y>
-inline bool signbit(const Y& val)
-{
- switch(fpclassify(val))
- {
- case _FPCLASS_SNAN:
- case _FPCLASS_QNAN:
- //whatever.
-
- case _FPCLASS_NINF:
- case _FPCLASS_NN:
- case _FPCLASS_ND:
- case _FPCLASS_NZ: return(true);
-
- case _FPCLASS_PZ:
- case _FPCLASS_PD:
- case _FPCLASS_PN:
- case _FPCLASS_PINF: return(false);
-
- }
- return(false);
-}
-
-template<class Y>
inline Y trunc(const Y& val)
{
if(val > 0) return std::floor(val);
Modified: sandbox/units/boost/units/detail/cmath_mwcw_impl.hpp
==============================================================================
--- sandbox/units/boost/units/detail/cmath_mwcw_impl.hpp (original)
+++ sandbox/units/boost/units/detail/cmath_mwcw_impl.hpp 2008-05-13 17:08:38 EDT (Tue, 13 May 2008)
@@ -28,30 +28,6 @@
namespace detail {
template<class Y>
-inline bool isfinite BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
-{
- return isfinite(val);
-}
-
-template<class Y>
-inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
-{
- return isinf(val);
-}
-
-template<class Y>
-inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
-{
- return isnan(val);
-}
-
-template<class Y>
-inline bool isnormal BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
-{
- return isnormal(val);
-}
-
-template<class Y>
inline bool isgreater BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& v1,const Y& v2)
{
return ::isgreater(v1,v2);
@@ -88,36 +64,6 @@
}
template<class Y>
-inline Y abs BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
-{
- return std::abs(val);
-}
-
-template<class Y>
-inline Y ceil BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
-{
- return std::ceil(val);
-}
-
-template<class Y>
-inline Y copysign BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& v1,const Y& v2)
-{
- return std::copysign(v1,v2);
-}
-
-template<class Y>
-inline Y fabs BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
-{
- return std::fabs(val);
-}
-
-template<class Y>
-inline Y floor BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
-{
- return std::floor(val);
-}
-
-template<class Y>
inline Y fdim BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& v1,const Y& v2)
{
return std::fdim(v1,v2);
@@ -141,18 +87,6 @@
return std::fmin(v1,v2);
}
-template<class Y>
-inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
-{
- return fpclassify(val);
-}
-
-template<class Y>
-inline Y hypot BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& v1,const Y& v2)
-{
- return std::hypot(v1,v2);
-}
-
//template<class Y>
//inline long long llrint BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
//{
@@ -190,18 +124,6 @@
}
template<class Y>
-inline Y round BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
-{
- return std::round(val);
-}
-
-template<class Y>
-inline bool signbit BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
-{
- return signbit(val);
-}
-
-template<class Y>
inline Y trunc BOOST_PREVENT_MACRO_SUBSTITUTION (const Y& val)
{
return std::trunc(val);
Modified: sandbox/units/libs/units/test/test_cmath.cpp
==============================================================================
--- sandbox/units/libs/units/test/test_cmath.cpp (original)
+++ sandbox/units/libs/units/test/test_cmath.cpp 2008-05-13 17:08:38 EDT (Tue, 13 May 2008)
@@ -128,10 +128,10 @@
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()));
- BOOST_CHECK((bu::round)(E4) == -3.0*bu::joules);
- BOOST_CHECK((bu::round)(E5) == 3.0*bu::joules);
- BOOST_CHECK((bu::signbit)(E4) == true);
- BOOST_CHECK((bu::signbit)(E5) == false);
+ 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_CHECK((bu::signbit)(E4) == 1);
+ BOOST_CHECK((bu::signbit)(E5) == 0);
BOOST_CHECK((bu::trunc)(E4) == -2.0*bu::joules);
BOOST_CHECK((bu::trunc)(E5) == 2.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