From 7f1a45870a2072e4575615959cd2ede218124ce2 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Thu, 21 Apr 2011 18:11:37 +0000 Subject: [PATCH] Change fp_traits to handle sign manipulation separately from fp-classification. Fixes some Linux/GCC regressions but not yet all. [SVN r71405] --- .../special_functions/detail/fp_traits.hpp | 3 +- include/boost/math/special_functions/sign.hpp | 30 +++++++------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/include/boost/math/special_functions/detail/fp_traits.hpp b/include/boost/math/special_functions/detail/fp_traits.hpp index 0f311b639..54d45917b 100644 --- a/include/boost/math/special_functions/detail/fp_traits.hpp +++ b/include/boost/math/special_functions/detail/fp_traits.hpp @@ -552,12 +552,13 @@ struct select_native template struct fp_traits { + typedef BOOST_DEDUCED_TYPENAME size_to_precision::value>::type precision; #if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && !defined(BOOST_MATH_DISABLE_STD_FPCLASSIFY) typedef typename select_native::type type; #else - typedef BOOST_DEDUCED_TYPENAME size_to_precision::value>::type precision; typedef fp_traits_non_native type; #endif + typedef fp_traits_non_native sign_change_type; }; //------------------------------------------------------------------------------ diff --git a/include/boost/math/special_functions/sign.hpp b/include/boost/math/special_functions/sign.hpp index 405bfc021..3163fc23e 100644 --- a/include/boost/math/special_functions/sign.hpp +++ b/include/boost/math/special_functions/sign.hpp @@ -66,14 +66,6 @@ namespace detail { // Changesign -#ifdef BOOST_MATH_USE_STD_FPCLASSIFY - template - inline int changesign_impl(T x, native_tag const&) - { - return -x; - } -#endif - template inline T (changesign_impl)(T x, generic_tag const&) { @@ -90,7 +82,7 @@ namespace detail { template inline T changesign_impl(T x, ieee_copy_all_bits_tag const&) { - typedef BOOST_DEDUCED_TYPENAME fp_traits::type traits; + typedef BOOST_DEDUCED_TYPENAME fp_traits::sign_change_type traits; BOOST_DEDUCED_TYPENAME traits::bits a; traits::get_bits(x,a); @@ -102,7 +94,7 @@ namespace detail { template inline T (changesign_impl)(T x, ieee_copy_leading_bits_tag const&) { - typedef BOOST_DEDUCED_TYPENAME fp_traits::type traits; + typedef BOOST_DEDUCED_TYPENAME fp_traits::sign_change_type traits; BOOST_DEDUCED_TYPENAME traits::bits a; traits::get_bits(x,a); @@ -115,7 +107,7 @@ namespace detail { } // namespace detail template int (signbit)(T x) -{ //!< \brief return true if floating-point type T is NaN (Not A Number). +{ typedef typename detail::fp_traits::type traits; typedef typename traits::method method; typedef typename boost::is_floating_point::type fp_tag; @@ -128,22 +120,22 @@ inline int sign BOOST_NO_MACRO_EXPAND(const T& z) return (z == 0) ? 0 : (boost::math::signbit)(z) ? -1 : 1; } -template -inline T copysign BOOST_NO_MACRO_EXPAND(const T& x, const T& y) -{ - BOOST_MATH_STD_USING - return fabs(x) * ((boost::math::signbit)(y) ? -1 : 1); -} - template T (changesign)(T x) { //!< \brief return unchanged binary pattern of x, except for change of sign bit. - typedef typename detail::fp_traits::type traits; + typedef typename detail::fp_traits::sign_change_type traits; typedef typename traits::method method; typedef typename boost::is_floating_point::type fp_tag; return detail::changesign_impl(x, method()); } +template +inline T copysign BOOST_NO_MACRO_EXPAND(const T& x, const T& y) +{ + BOOST_MATH_STD_USING + return (boost::math::signbit)(x) != (boost::math::signbit)(y) ? (boost::math::changesign)(x) : x; +} + } // namespace math } // namespace boost