Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71370 - trunk/boost/math/special_functions
From: pbristow_at_[hidden]
Date: 2011-04-18 12:19:27


Author: pbristow
Date: 2011-04-18 12:19:26 EDT (Mon, 18 Apr 2011)
New Revision: 71370
URL: http://svn.boost.org/trac/boost/changeset/71370

Log:
Changesign addded.
Text files modified:
   trunk/boost/math/special_functions/sign.hpp | 52 +++++++++++++++++++++++++++++++++++++++
   1 files changed, 51 insertions(+), 1 deletions(-)

Modified: trunk/boost/math/special_functions/sign.hpp
==============================================================================
--- trunk/boost/math/special_functions/sign.hpp (original)
+++ trunk/boost/math/special_functions/sign.hpp 2011-04-18 12:19:26 EDT (Mon, 18 Apr 2011)
@@ -1,4 +1,7 @@
 // (C) Copyright John Maddock 2006.
+// (C) Copyright Johan Rade 2006.
+// (C) Copyright Paul A. Bristow 2011 (added changesign).
+
 // Use, modification and distribution are subject to the
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -58,10 +61,48 @@
 
         return a & traits::sign ? 1 : 0;
     }
+
+ template<class T>
+ inline T changesign_impl(T x, ieee_copy_all_bits_tag const&)
+ {
+ typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits;
+
+ BOOST_DEDUCED_TYPENAME traits::bits a;
+ traits::get_bits(x,a);
+ a ^= traits::sign;
+ traits::set_bits(x,a);
+ return x;
+ }
+
+ template<class T>
+ inline T (changesign_impl)(T x, ieee_copy_leading_bits_tag const&)
+ {
+ typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits;
+
+ BOOST_DEDUCED_TYPENAME traits::bits a;
+ traits::get_bits(x,a);
+ a ^= traits::sign;
+ traits::set_bits(x,a);
+ return x;
+ }
+
+ template<class T>
+ inline T (changesign_impl)(T x, generic_tag<true> const&)
+ {
+ return -x;
+ }
+
+ template<class T>
+ inline T (changesign_impl)(T x, generic_tag<false> const&)
+ {
+ return -x;
+ }
+
+
 } // namespace detail
 
 template<class T> int (signbit)(T x)
-{ //!< \brief return true if floating-point type t is NaN (Not A Number).
+{ //!< \brief return true if floating-point type T is NaN (Not A Number).
    typedef typename detail::fp_traits<T>::type traits;
    typedef typename traits::method method;
    typedef typename boost::is_floating_point<T>::type fp_tag;
@@ -81,6 +122,15 @@
       return fabs(x) * ((boost::math::signbit)(y) ? -1 : 1);
 }
 
+template<class T> T (changesign)(T x)
+{
+ typedef typename detail::fp_traits<T>::type traits;
+ typedef typename traits::method method;
+ typedef typename boost::is_floating_point<T>::type fp_tag;
+
+ return detail::changesign_impl(x, method());
+}
+
 } // namespace math
 } // namespace boost
 


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