00001 00002 /* 00003 The Extended Integer (XInt) Library 00004 A fast, portable C++ library for multi-precision integer math 00005 Copyright 2010 by Chad Nelson 00006 00007 Distributed under the Boost Software License, Version 1.0. 00008 See accompanying file LICENSE_1_0.txt or copy at 00009 http://www.boost.org/LICENSE_1_0.txt 00010 00011 See http://www.boost.org/libs/xint for library home page. 00012 */ 00013 00020 #ifndef BOOST_INCLUDED_XINT_ANDORXOR_HPP 00021 #define BOOST_INCLUDED_XINT_ANDORXOR_HPP 00022 00024 namespace boost { 00025 namespace xint { 00026 namespace detail { 00027 00028 BOOST_XINT_RAWINT_TPL 00029 BOOST_XINT_RAWINT& BOOST_XINT_RAWINT::operator&=(const BOOST_XINT_RAWINT n) { 00030 std::size_t len = (std::min)(length, n.length); 00031 const digit_t *ns = n.digits(), *nse = ns + len; 00032 digit_t *t = digits(len, realloc::extend); 00033 while (ns != nse) *t++ &= *ns++; 00034 length = len; 00035 trim(); 00036 return *this; 00037 } 00038 00039 BOOST_XINT_RAWINT_TPL 00040 BOOST_XINT_RAWINT& BOOST_XINT_RAWINT::operator|=(const BOOST_XINT_RAWINT n) { 00041 std::size_t len = (std::max)(length, n.length); 00042 if (length > n.length) { 00043 const digit_t *ns = n.digits(), *nse = ns + n.length; 00044 digit_t *t = digits(len, realloc::extend); 00045 while (ns != nse) *t++ |= *ns++; 00046 } else { 00047 const digit_t *ns = n.digits(), *nse = ns + len; 00048 digit_t *t = digits(len, realloc::extend), *te = t + length; 00049 while (t != te) *t++ |= *ns++; 00050 while (ns != nse) *t++ = *ns++; 00051 length = len; 00052 } 00053 trim(); 00054 return *this; 00055 } 00056 00057 BOOST_XINT_RAWINT_TPL 00058 BOOST_XINT_RAWINT& BOOST_XINT_RAWINT::operator^=(const BOOST_XINT_RAWINT n) { 00059 std::size_t len = (std::max)(length, n.length); 00060 if (length > n.length) { 00061 const digit_t *ns = n.digits(), *nse = ns + n.length; 00062 digit_t *t = digits(len, realloc::extend); 00063 while (ns != nse) *t++ ^= *ns++; 00064 } else { 00065 const digit_t *ns = n.digits(), *nse = ns + len; 00066 digit_t *t = digits(len, realloc::extend), *te = t + length; 00067 while (t != te) *t++ ^= *ns++; 00068 while (ns != nse) *t++ = *ns++; 00069 length = len; 00070 } 00071 trim(); 00072 return *this; 00073 } 00074 00075 BOOST_XINT_RAWINT_TPL 00076 BOOST_XINT_RAWINT operator&(const BOOST_XINT_RAWINT n1, const BOOST_XINT_RAWINT 00077 n2) 00078 { 00079 return BOOST_XINT_RAWINT(n1) &= n2; 00080 } 00081 00082 BOOST_XINT_RAWINT_TPL 00083 BOOST_XINT_RAWINT operator|(const BOOST_XINT_RAWINT n1, const BOOST_XINT_RAWINT 00084 n2) 00085 { 00086 return BOOST_XINT_RAWINT(n1) |= n2; 00087 } 00088 00089 BOOST_XINT_RAWINT_TPL 00090 BOOST_XINT_RAWINT operator^(const BOOST_XINT_RAWINT n1, const BOOST_XINT_RAWINT 00091 n2) 00092 { 00093 return BOOST_XINT_RAWINT(n1) ^= n2; 00094 } 00095 00096 } // namespace detail 00097 } // namespace xint 00098 } // namespace boost 00100 00101 #endif // BOOST_INCLUDED_XINT_ANDORXOR_HPP
© Copyright Chad Nelson, 2010-2011. 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)