PseudoLongProduct.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_groebner_PseudoLongProduct_h_
#define polybori_groebner_PseudoLongProduct_h_
// include basic definitions
#include "groebner_defs.h"
#include "PseudoLongLong.h"
#include "BitMask.h"
BEGIN_NAMESPACE_PBORIGB
class PseudoLongProduct:
protected BitMask<sizeof(unsigned long)*4> {
public:
typedef unsigned long long_type;
PseudoLongProduct(const long_type& first, const long_type& second):
most(high(first)*high(second)), least(low(first)*low(second)) {
long_type mixed = high(least) + high(first)*low(second);
most += high(mixed);
mixed = low(mixed) + low(first)*high(second);
most += high(mixed);
least = shift(mixed) + low(least);
}
bool greater(long_type rhs) const {
return (most > 0) || (least > rhs);
}
template <long_type MaxLow>
bool greater(const PseudoLongLong<0, MaxLow>&) const {
return greater(MaxLow);
}
template <long_type MaxHigh, long_type MaxLow>
bool greater(const PseudoLongLong<MaxHigh, MaxLow>&) const {
return (most > MaxHigh) || ( (most == MaxHigh) && (least > MaxLow) );
}
private:
long_type most, least;
};
template <class RhsType>
inline bool
operator> (PseudoLongProduct lhs, const RhsType& rhs) {
return lhs.greater(rhs);
}
END_NAMESPACE_PBORIGB
#endif /* polybori_groebner_PseudoLongProduct_h_ */