Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63271 - sandbox/SOC/2010/bits_and_ints/boost/integer
From: muriloufg_at_[hidden]
Date: 2010-06-23 19:18:34


Author: murilov
Date: 2010-06-23 19:18:30 EDT (Wed, 23 Jun 2010)
New Revision: 63271
URL: http://svn.boost.org/trac/boost/changeset/63271

Log:
Added safe_avg and swap functions
Added:
   sandbox/SOC/2010/bits_and_ints/boost/integer/safe_avg.hpp (contents, props changed)
   sandbox/SOC/2010/bits_and_ints/boost/integer/swap.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/bits_and_ints/boost/integer/bits_and_ints.hpp | 7 +++++++
   1 files changed, 7 insertions(+), 0 deletions(-)

Modified: sandbox/SOC/2010/bits_and_ints/boost/integer/bits_and_ints.hpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/boost/integer/bits_and_ints.hpp (original)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/bits_and_ints.hpp 2010-06-23 19:18:30 EDT (Wed, 23 Jun 2010)
@@ -19,5 +19,12 @@
 #include <boost/integer/static_bit_reversal.hpp>
 #include <boost/integer/sign.hpp>
 #include <boost/integer/same_sign.hpp>
+#include <boost/integer/pop_count.hpp>
+#include <boost/integer/interleave.hpp>
+#include <boost/integer/count_trailing_zeros.hpp>
+#include <boost/integer/clear_least_bit_set.hpp>
+#include <boost/integer/swap.hpp>
+#include <boost/integer/safe_avg.hpp>
+#include <boost/integer/round_power_2.hpp>
 
 #endif
\ No newline at end of file

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/safe_avg.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/safe_avg.hpp 2010-06-23 19:18:30 EDT (Wed, 23 Jun 2010)
@@ -0,0 +1,32 @@
+// Boost integer/safe_avg.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.
+
+/*
+ * Given two integer values x and y, the (floor of the) average normally
+ * would be computed by (x+y)/2; unfortunately,
+ * this can yield incorrect results due to overflow.
+ *
+ * `safe_avg(x, y)' ensures that no overflow will happen even if (x+y)
+ * overflows the range of T.
+ */
+
+#ifndef BOOST_SAFE_AVG_INCLUDED
+#define BOOST_SAFE_AVG_INCLUDED
+
+namespace boost {
+
+template <typename T>
+inline T safe_avg(T x, T y)
+{
+ return (x & y) + ((x ^ y) >> 1);
+} // safe_avg
+
+} // boost
+
+#endif
\ No newline at end of file

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/swap.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/swap.hpp 2010-06-23 19:18:30 EDT (Wed, 23 Jun 2010)
@@ -0,0 +1,30 @@
+// Boost integer/swap.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.
+
+/*
+ * This function swaps the values of x and y without a temporary variable.
+ */
+
+#ifndef BOOST_SWAP_INCLUDED
+#define BOOST_SWAP_INCLUDED
+
+namespace boost
+{
+
+template <typename T>
+inline void swap(T& x, T& y)
+{
+ x ^= y;
+ y ^= x;
+ x ^= y;
+} // swap
+
+} // boost
+
+#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