Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63791 - sandbox/SOC/2010/bits_and_ints/boost/integer
From: muriloufg_at_[hidden]
Date: 2010-07-09 15:57:01


Author: murilov
Date: 2010-07-09 15:56:57 EDT (Fri, 09 Jul 2010)
New Revision: 63791
URL: http://svn.boost.org/trac/boost/changeset/63791

Log:
Implemented the run-time and compile-times version of isign function (transfer of sign function)
Added tests for isign functions:

Added:
   sandbox/SOC/2010/bits_and_ints/boost/integer/isign.hpp (contents, props changed)
   sandbox/SOC/2010/bits_and_ints/boost/integer/static_isign.hpp (contents, props changed)

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/isign.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/isign.hpp 2010-07-09 15:56:57 EDT (Fri, 09 Jul 2010)
@@ -0,0 +1,32 @@
+// Boost integer/isign.hpp header file ------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 2010.
+// Distributed under 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
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_ISIGN_INCLUDED
+#define BOOST_ISIGN_INCLUDED
+
+namespace boost {
+
+/*
+ * `isign' or transfer of sign function is defined by:
+ *
+ * isign(x, y) =
+ * abs(x), if y is greater than or equal 0,
+ * -abs(x), if y is less than 0.
+ */
+
+template <typename T>
+T isign(T x, T y)
+{
+ const T tmp = (x ^ y) >> (sizeof(T) * 8 - 1);
+ return (x ^ tmp) - tmp;
+}
+
+} // boost
+
+#endif

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/static_isign.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/static_isign.hpp 2010-07-09 15:56:57 EDT (Fri, 09 Jul 2010)
@@ -0,0 +1,60 @@
+// Boost integer/static_isign.hpp header file ------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 2010.
+// Distributed under 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
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_STATIC_ISIGN_INCLUDED
+#define BOOST_STATIC_ISIGN_INCLUDED
+
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/integral_c.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_integral.hpp>
+#include <boost/integer/is_integral_constant.hpp>
+
+namespace boost {
+
+/*
+ * MPL and static version of isign (transfer of sign function)
+ */
+
+
+namespace mpl {
+
+/*
+ * This metafunction requires IC1 and IC2 to be mpl::integral_c<> types
+ */
+template <typename IC1, typename IC2,
+ class Enable = typename enable_if<
+ and_<
+ is_integral_constant<IC1>,
+ is_integral_constant<IC2>
+ >
+ >::type
+>
+struct isign : integral_c<typename IC1::value_type,
+ ((IC1::value ^ ((IC1::value ^ IC2::value) >> sizeof(typename IC1::value_type) * 8 - 1))
+ - ((IC1::value ^ IC2::value) >> sizeof(typename IC1::value_type) * 8 - 1))
+>
+{};
+
+} // mpl
+
+/*
+ * This metafunction requires T to be an integral type
+ */
+template <typename T, T Value1, T Value2,
+ class Enable = typename enable_if< is_integral<T> >::type>
+struct static_isign : mpl::isign<
+ mpl::integral_c<T, Value1>,
+ mpl::integral_c<T, Value2>
+>
+{};
+
+} // boost
+
+#endif


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