Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64411 - in sandbox/SOC/2010/bits_and_ints: boost/integer libs/integer/test
From: muriloufg_at_[hidden]
Date: 2010-07-28 10:23:23


Author: murilov
Date: 2010-07-28 10:23:22 EDT (Wed, 28 Jul 2010)
New Revision: 64411
URL: http://svn.boost.org/trac/boost/changeset/64411

Log:
Added rotate_left and rotate_right functions under header rotate.hpp
Added:
   sandbox/SOC/2010/bits_and_ints/boost/integer/rotate.hpp (contents, props changed)
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/rotate_test.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 | 1 +
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/find_first_one_string_test.cpp | 2 +-
   2 files changed, 2 insertions(+), 1 deletions(-)

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/rotate.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/rotate.hpp 2010-07-28 10:23:22 EDT (Wed, 28 Jul 2010)
@@ -0,0 +1,34 @@
+// Boost integer/rotate.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_ROTATE_INCLUDED
+#define BOOST_ROTATE_INCLUDED
+
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_integral.hpp>
+#include <boost/type_traits/make_unsigned.hpp>
+
+namespace boost {
+
+template <typename T>
+inline typename enable_if<is_integral<T>, T>::type
+rotate_left(T value, unsigned length)
+{
+ return (value << length) | (typename make_unsigned<T>::type(value) >> ((sizeof(T) << 3) - length));
+}
+
+template <typename T>
+inline typename enable_if<is_integral<T>, T>::type
+rotate_right(T value, unsigned length)
+{
+ return (typename make_unsigned<T>::type(value) >> length) | (value << ((sizeof(T) << 3) - length));
+}
+
+}
+#endif
\ No newline at end of file

Modified: sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 (original)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 2010-07-28 10:23:22 EDT (Wed, 28 Jul 2010)
@@ -31,6 +31,7 @@
                 [ run inc_rev_test.cpp ]
                 [ run isqrt_test.cpp ]
                 [ run find_first_one_string_test.cpp ]
+ [ run rotate_test.cpp ]
                 [ compile cstdint_include_test.cpp ]
                 [ compile integer_traits_include_test.cpp ]
                 [ compile integer_include_test.cpp ]

Modified: sandbox/SOC/2010/bits_and_ints/libs/integer/test/find_first_one_string_test.cpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/libs/integer/test/find_first_one_string_test.cpp (original)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/find_first_one_string_test.cpp 2010-07-28 10:23:22 EDT (Wed, 28 Jul 2010)
@@ -40,4 +40,4 @@
 #endif
         
         return boost::report_errors();
-}
\ No newline at end of file
+}

Added: sandbox/SOC/2010/bits_and_ints/libs/integer/test/rotate_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/rotate_test.cpp 2010-07-28 10:23:22 EDT (Wed, 28 Jul 2010)
@@ -0,0 +1,54 @@
+// Boost integer/rotate.hpp test program ----------------------//
+// (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
+
+
+#include <iostream>
+#include <boost/cstdint.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/integer/rotate.hpp>
+
+#define ROTATE_L_TEST(x, n, y) \
+BOOST_TEST((::boost::rotate_left(x, n) == y))
+
+#define ROTATE_R_TEST(x, n, y) \
+BOOST_TEST((::boost::rotate_right(x, n) == y))
+
+int main()
+{
+ ROTATE_L_TEST(0x0, 1, 0);
+ ROTATE_L_TEST(0x0, 30, 0);
+ ROTATE_L_TEST(0xF0000000, 4, 0xF);
+ ROTATE_L_TEST(0xFF000000, 4, 0xF000000F);
+ ROTATE_L_TEST(0xFF000000, 8, 0xFF);
+ ROTATE_L_TEST(0xA0000000, 1, 0x40000001);
+ ROTATE_L_TEST(0xA0000000, 2, 0x80000002);
+ ROTATE_L_TEST(0xA0000000, 3, 0x5);
+ ROTATE_L_TEST(0xC, 8, 0xC00);
+ ROTATE_L_TEST(0xFFFFFFFF, 4, 0xFFFFFFFF);
+ ROTATE_L_TEST(0xFFFFFFFF, 31, 0xFFFFFFFF);
+ ROTATE_L_TEST(0x00000002, 31, 0x1);
+ ROTATE_L_TEST(0x12345678, 4, 0x23456781);
+
+#ifndef BOOST_HAS_NO_INT64_T
+
+ ROTATE_L_TEST((uint64_t)0x0, 1, 0);
+ ROTATE_L_TEST((uint64_t)0x0, 30, 0);
+ ROTATE_L_TEST((uint64_t)0xF000000000000000, 4, 0xF);
+ ROTATE_L_TEST((uint64_t)0xFF00000000000000, 4, 0xF00000000000000F);
+ ROTATE_L_TEST((uint64_t)0xFF00000000000000, 8, 0xFF);
+ ROTATE_L_TEST((uint64_t)0xA000000000000000, 1, 0x4000000000000001);
+ ROTATE_L_TEST((int64_t)0xA000000000000000, 2, (int64_t)0x8000000000000002);
+ ROTATE_L_TEST((int64_t)0xA000000000000000, 3, (int64_t)0x5);
+ ROTATE_L_TEST((int64_t)0xC, 8, (int64_t)0xC00);
+ ROTATE_L_TEST((int64_t)0xFFFFFFFFFFFFFFFF, 4, (int64_t)0xFFFFFFFFFFFFFFFF);
+ ROTATE_L_TEST((int64_t)0xFFFFFFFFFFFFFFFF, 63, (int64_t)0xFFFFFFFFFFFFFFFF);
+ ROTATE_L_TEST((int64_t)0x0000000000000002, 63, (int64_t)0x1);
+ ROTATE_L_TEST((int64_t)0x123456789ABCDEF0, 4, (int64_t)0x23456789ABCDEF01);
+
+#endif
+
+ return boost::report_errors();
+}


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