Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64510 - sandbox/SOC/2010/bits_and_ints/boost/integer
From: muriloufg_at_[hidden]
Date: 2010-07-31 15:20:18


Author: murilov
Date: 2010-07-31 15:20:18 EDT (Sat, 31 Jul 2010)
New Revision: 64510
URL: http://svn.boost.org/trac/boost/changeset/64510

Log:
Added round right shift function
Added:
   sandbox/SOC/2010/bits_and_ints/boost/integer/rrshift.hpp (contents, props changed)

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/rrshift.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/rrshift.hpp 2010-07-31 15:20:18 EDT (Sat, 31 Jul 2010)
@@ -0,0 +1,30 @@
+// Boost integer/rrshift.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_RRSHIFT_INCLUDED
+#define BOOST_RRSHIFT_INCLUDED
+
+#include <boost/integer/sign.hpp>
+#include <boost/type_traits/make_unsigned.hpp>
+
+namespace boost {
+
+/*
+ * rrshift function perform a right shift rounding towards 0.
+ */
+
+template <typename T>
+inline T rrshift(T value, unsigned shift)
+{
+ return sign(value) * (typename make_unsigned<T>::type(sign(value) * value) >> shift);
+}
+
+}
+
+#endif
\ No newline at end of file


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