[SCM] polybori: Polynomials over Boolean Rings branch, upstream-hg, updated. b4a5cffaa908c53e1d958a42110f8c4dad853aa3
Alexander Dreyer
adreyer at gmx.de
Fri Mar 23 08:01:51 UTC 2012
The following commit has been merged in the upstream-hg branch:
commit e78ac9f934ed897f1e0a055462e25957b6b28e11
Author: Alexander Dreyer <adreyer at gmx.de>
Date: Wed Feb 29 22:38:43 2012 +0100
FIX: better delayed product
diff --git a/groebner/include/polybori/groebner/BitMask.h b/groebner/include/polybori/groebner/BitMask.h
index 16997b7..8790a8d 100644
--- a/groebner/include/polybori/groebner/BitMask.h
+++ b/groebner/include/polybori/groebner/BitMask.h
@@ -32,7 +32,7 @@ class BitMask;
template <>
class BitMask<0> {
public:
- enum { nbits = 0, mask = 0 };
+ enum { nbits = 0, mask = (unsigned long)0 };
unsigned long low(const unsigned long& value) const { return 0; }
const unsigned long& high(const unsigned long& value) const { return value; }
@@ -44,7 +44,7 @@ public:
template <unsigned NBits>
class BitMask {
public:
- enum { nbits = NBits, mask = (BitMask<nbits-1>::mask << 1) + 1};
+ enum { nbits = NBits, mask = ((unsigned long)(BitMask<nbits-1>::mask) << 1) | 0x1};
unsigned long low(const unsigned long& value) const {
return value & mask;
@@ -64,7 +64,7 @@ template <>
class BitMask<sizeof(unsigned long)*8> {
public:
enum { nbits = sizeof(unsigned long)*8,
- mask = (BitMask<nbits-1>::mask << 1) + 1};
+ mask = ((unsigned long)(BitMask<nbits-1>::mask) << 1) | 0x1};
const unsigned long& low(const unsigned long& value) const { return value; }
unsigned long high(const unsigned long& value) const { return 0; }
diff --git a/groebner/include/polybori/groebner/DelayedLongProduct.h b/groebner/include/polybori/groebner/DelayedLongProduct.h
index f0cdc3f..dc74d88 100644
--- a/groebner/include/polybori/groebner/DelayedLongProduct.h
+++ b/groebner/include/polybori/groebner/DelayedLongProduct.h
@@ -32,7 +32,7 @@ BEGIN_NAMESPACE_PBORIGB
**/
class DelayedLongProduct:
- protected std::pair<unsigned long, unsigned long>,
+ public std::pair<unsigned long, unsigned long>,
protected BitMask<sizeof(unsigned long)*4> {
typedef std::pair<unsigned long, unsigned long> base;
@@ -52,27 +52,32 @@ public:
}
/// compare carry-over savely with represented by two unsigned longs
+ template <long_type MaxLow>
+ bool greater(const PseudoLongLong<0, MaxLow>&) const {
+ return greater(MaxLow);
+ }
+
+ /// compare carry-over savely with represented by two unsigned longs
template <long_type MaxHigh, long_type MaxLow>
bool greater(const PseudoLongLong<MaxHigh, MaxLow>&) const {
- if (second == 0)
- return false;
-
- BitMask<sizeof(long_type)*8 - NBitsUsed<MaxHigh>::value > front;
- const long_type front_part = (front.shift(MaxHigh) + front.high(MaxLow));
- long_type divided = front_part / second;
+ long_type least = low(first)*low(second);
+ long_type mixed = high(least) + high(first)*low(second);
+ long_type most = high(mixed) + high(first)*high(second);
+ if (most > MaxHigh)
+ return true;
- return (front.high(divided) == 0) &&
- (first > front.back(divided)) &&
- (first - front.back(divided) >
- (front.back(front_part%second)+ front.low(MaxLow) ) / second);
+ mixed = low(mixed) + low(first)*high(second);
+ most += high(mixed);
+ least = shift(mixed) + low(least);
+ return (most > MaxHigh) || ( (most == MaxHigh) && (least > MaxLow) );
}
};
template <class RhsType>
inline bool
operator> (DelayedLongProduct lhs, const RhsType& rhs) {
- return lhs.greater(rhs);
+ return lhs.greater(rhs);
}
diff --git a/testsuite/src/DelayedLongProductTest.cc b/testsuite/src/DelayedLongProductTest.cc
index 3ba38cc..5854da4 100644
--- a/testsuite/src/DelayedLongProductTest.cc
+++ b/testsuite/src/DelayedLongProductTest.cc
@@ -42,29 +42,30 @@ BOOST_AUTO_TEST_CASE(test_less) {
BOOST_TEST_MESSAGE( "operator<..." );
- BOOST_CHECK_EQUAL((DelayedLongProduct((unsigned long)(-1),
- (unsigned long)(-1)) >
- PseudoLongLong<(unsigned long)(-1), (unsigned long)(-1)>()), true);
+ BOOST_CHECK_EQUAL((DelayedLongProduct(long_type(-1),
+ long_type(-1)) >
+ PseudoLongLong<long_type(-1), long_type(-1)>()), false);
- BOOST_CHECK_EQUAL((DelayedLongProduct((unsigned long)(-1),
- (unsigned long)(-1)) >
- PseudoLongLong<(unsigned long)(-1), 0>()), false);
+ BOOST_CHECK_EQUAL((DelayedLongProduct(long_type(-1),
+ long_type(-1)) >
+ PseudoLongLong<long_type(-1), 0>()), false);
- BOOST_CHECK_EQUAL((DelayedLongProduct((unsigned long)(-1),
- (unsigned long)(-1)) >
- PseudoLongLong<(unsigned long)(-1)/2,
- (unsigned long)(-1)>()), true);
- BOOST_CHECK_EQUAL((DelayedLongProduct((unsigned long)(2)<< nhalf,
- (unsigned long)(2)<< nhalf) >
- PseudoLongLong<3,(unsigned long)(-1)>()), true);
+ BOOST_CHECK_EQUAL((DelayedLongProduct(long_type(-1),
+ long_type(-1)) >
+ PseudoLongLong<long_type(-1)/2,
+ long_type(-1)>()), true);
- BOOST_CHECK_EQUAL((DelayedLongProduct((unsigned long)(2)<< nhalf ,
- (unsigned long)(2)<< nhalf ) >
+ BOOST_CHECK_EQUAL((DelayedLongProduct(long_type(2)<< nhalf,
+ long_type(2)<< nhalf) >
+ PseudoLongLong<3,long_type(-1)>()), true);
+
+ BOOST_CHECK_EQUAL((DelayedLongProduct(long_type(2)<< nhalf ,
+ long_type(2)<< nhalf ) >
PseudoLongLong<4,0>()), false);
- BOOST_CHECK_EQUAL((DelayedLongProduct((unsigned long)(2)<< nhalf,
- (unsigned long)(2)<< nhalf )>
+ BOOST_CHECK_EQUAL((DelayedLongProduct(long_type(2)<< nhalf,
+ long_type(2)<< nhalf )>
PseudoLongLong<4,1>()), false);
BOOST_CHECK_EQUAL((DelayedLongProduct(5, 7) > 34), true);
--
polybori: Polynomials over Boolean Rings
More information about the debian-science-commits
mailing list