PolyBoRi
|
00001 // -*- c++ -*- 00002 //***************************************************************************** 00014 //***************************************************************************** 00015 00016 #ifndef polybori_groebner_PseudoLongProduct_h_ 00017 #define polybori_groebner_PseudoLongProduct_h_ 00018 00019 // include basic definitions 00020 #include "groebner_defs.h" 00021 #include "PseudoLongLong.h" 00022 #include "BitMask.h" 00023 00024 BEGIN_NAMESPACE_PBORIGB 00025 00032 class PseudoLongProduct: 00033 protected BitMask<sizeof(unsigned long)*4> { 00034 00035 public: 00036 typedef unsigned long long_type; 00037 00038 PseudoLongProduct(const long_type& first, const long_type& second): 00039 most(high(first)*high(second)), least(low(first)*low(second)) { 00040 00041 long_type mixed = high(least) + high(first)*low(second); 00042 most += high(mixed); 00043 00044 mixed = low(mixed) + low(first)*high(second); 00045 most += high(mixed); 00046 00047 least = shift(mixed) + low(least); 00048 } 00049 00051 bool greater(long_type rhs) const { 00052 return (most > 0) || (least > rhs); 00053 } 00054 00056 template <long_type MaxLow> 00057 bool greater(const PseudoLongLong<0, MaxLow>&) const { 00058 return greater(MaxLow); 00059 } 00060 00062 template <long_type MaxHigh, long_type MaxLow> 00063 bool greater(const PseudoLongLong<MaxHigh, MaxLow>&) const { 00064 return (most > MaxHigh) || ( (most == MaxHigh) && (least > MaxLow) ); 00065 } 00066 00067 private: 00068 long_type most, least; 00069 }; 00070 00071 template <class RhsType> 00072 inline bool 00073 operator> (PseudoLongProduct lhs, const RhsType& rhs) { 00074 return lhs.greater(rhs); 00075 } 00076 00077 00078 00079 END_NAMESPACE_PBORIGB 00080 00081 #endif /* polybori_groebner_PseudoLongProduct_h_ */