hacky gmp wrapper for testing

3 views
Skip to first unread message

Isaac Dupree

unread,
Mar 30, 2013, 3:42:31 PM3/30/13
to lase...@googlegroups.com


// prevents mpz_class's clever optimizations,
// so that physical_quantity can handle it better.
// TODO do better.
class mpz {
mpz_class data_;
public:
mpz(){}
mpz(mpz_class d):data_(d){}
//template<typename T> mpz(T t) : data_(t) {}

explicit operator bool()const { return bool(data_); }

friend inline mpz operator*(mpz a, mpz b)
{ return mpz(a.data_ * b.data_); }
friend inline mpz operator+(mpz a) { return mpz(+a.data_); }
friend inline mpz operator-(mpz a) { return mpz(-a.data_); }
friend inline mpz abs(mpz a) { return mpz(a.data_ < 0 ? -a.data_ :
a.data_); }
friend inline mpz operator+(mpz a, mpz b) { return mpz(a.data_ + b.data_); }
friend inline mpz operator-(mpz a, mpz b) { return mpz(a.data_ - b.data_); }

friend inline mpz operator&(mpz a, mpz b) { return mpz(a.data_ & b.data_); }
friend inline mpz operator|(mpz a, mpz b) { return mpz(a.data_ | b.data_); }
friend inline mpz operator^(mpz a, mpz b) { return mpz(a.data_ ^ b.data_); }
friend inline mpz operator~(mpz a) { return mpz(~a); }

friend inline bool operator==(mpz a, mpz b) { return a.data_ == b.data_; }
friend inline bool operator!=(mpz a, mpz b) { return a.data_ != b.data_; }
friend inline bool operator<(mpz a, mpz b) { return a.data_ < b.data_; }
friend inline bool operator>(mpz a, mpz b) { return a.data_ > b.data_; }
friend inline bool operator>=(mpz a, mpz b) { return a.data_ >= b.data_; }
friend inline bool operator<=(mpz a, mpz b) { return a.data_ <= b.data_; }

friend inline mpz operator<<(mpz a, uint32_t shift)
{ return mpz(a.data_ << shift); }
friend inline mpz operator>>(mpz a, uint32_t shift)
{ return mpz(a.data_ >> shift); }

friend inline mpz& operator+=(mpz& a, mpz b) { a = a + b; return a; }
friend inline mpz& operator-=(mpz& a, mpz b) { a = a - b; return a; }
friend inline mpz& operator*=(mpz& a, mpz b) { a = a * b; return a; }
friend inline mpz& operator&=(mpz& a, mpz b) { a = a & b; return a; }
friend inline mpz& operator|=(mpz& a, mpz b) { a = a | b; return a; }
friend inline mpz& operator^=(mpz& a, mpz b) { a = a ^ b; return a; }
friend inline mpz& operator<<=(mpz& a, uint32_t shift) { a = a << shift;
return a; }
friend inline mpz& operator>>=(mpz& a, uint32_t shift) { a = a >> shift;
return a; }

friend inline mpz& operator++(mpz& a) { ++a.data_; return a; }
friend inline mpz operator++(mpz& a, int) { mpz old = a; ++a.data_;
return old; }
friend inline mpz& operator--(mpz& a) { --a.data_; return a; }
friend inline mpz operator--(mpz& a, int) { mpz old = a; ++a.data_;
return old; }

//Imagine taking the sqrt of a signed 8 bit value. Can it fit into 4 bits?
// sqrt(127) is 11.something, which is less than 15 (unsigned 4bit max) but
// greater than 7 (signed 4bit max). So we conservatively leave enough
space here.
friend inline mpz isqrt(mpz a)
{ return mpz(sqrt(a.data_)); }
//friend inline int32_t ilog2(mpz a) { return ; }

friend std::ostream& operator<<(std::ostream& os, mpz a) {
return os << a;
}
};
namespace std {
template<> struct numeric_limits<mpz> {
static const bool is_specialized = true;
static const bool is_integer = true;
static const bool is_signed = true;
static const int digits = INT_MAX;
static const int radix = 2;
};
}

signature.asc

Eli Dupree

unread,
Mar 30, 2013, 3:54:40 PM3/30/13
to lase...@googlegroups.com, Isaac Dupree
grand_structure.cpp:248:147: error: no match for �operator*� in �operator/(physical_quantity<Target, Units>, units<DimKinds ...>) [with Num = mpz; UnitsA = units<dim::ratio<1l, 1000000l>, dim::meter<1l> >; UB = {dim::second<2l>}; typename make_physical_quantity_type<Num, typename
units_impl::divide_units<UnitsA, units<DimKinds ...> >::type>::type = physical_quantity<mpz, units<dim::ratio<1l, 1000000l>, dim::meter<1l>, dim::second<-2l> > >]((operator*<{dim::second<1l>}, {dim::second<1l>}>((seconds, units<dim::second<1l> >()), (seconds, units<dim::second<1l> >())),
units_impl::units_cons<dim::second<2l>, units<>, false>::type())) * identity<1000l>((operator/<{dim::ratio<1l, 1000000000l>, dim::meter<1l>}, {dim::ratio<1l, 1000000l>, dim::meter<1l>}>((YO::distance_units, units<dim::ratio<1l, 1000000000l>, dim::meter<1l> >()), (operator*<{dim::ratio<1l,
1000000l>}, {dim::meter<1l>}>((micro, units<dim::ratio<1l, 1000000l> >()), (meters, units<dim::meter<1l> >())), units_impl::units_cons<dim::ratio<1l, 1000000l>, units<dim::meter<1l> >, false>::type())), units_impl::units_cons<dim::ratio<1l, 1000l>, units<>, false>::type()))�
grand_structure.cpp:248:147: note: candidates are:
grand_structure.cpp:248:147: note: operator*(int, int) <built-in>
grand_structure.cpp:248:147: note: no known conversion for argument 2 from �identity_units<1000l>::type {aka physical_quantity<short int, units<dim::ratio<1l, 1000l> > >}� to �int�
In file included from grand_structure.cpp:44:0:
../units.hpp:739:3: note: template<class AnyNum> constexpr typename physical_quantity<short int, units<dim::ratio<1l, 1000l> > >::rebase<decltype ((declval<typename boost::enable_if_c<get_units<Units>::is_nonunit_scalar, AnyNum>::type>() * declval<physical_quantity<short int, units<dim::ratio<1l,
1000l> > >::base_type>()))>::type operator*(AnyNum, physical_quantity<short int, units<dim::ratio<1l, 1000l> > >::this_t)
../units.hpp:739:3: note: template argument deduction/substitution failed:
../units.hpp: In substitution of �template<class AnyNum> constexpr typename physical_quantity<short int, units<dim::ratio<1l, 1000l> > >::rebase<decltype ((declval<typename boost::enable_if_c<get_units<Units>::is_nonunit_scalar, AnyNum>::type>() * declval<physical_quantity<short int,
units<dim::ratio<1l, 1000l> > >::base_type>()))>::type operator*(AnyNum, physical_quantity<short int, units<dim::ratio<1l, 1000l> > >::this_t) [with AnyNum = physical_quantity<mpz, units<dim::ratio<1l, 1000000l>, dim::meter<1l>, dim::second<-2l> > >]�:
grand_structure.cpp:248:147: required from here
../units.hpp:739:3: error: no type named �type� in �struct boost::enable_if_c<false, physical_quantity<mpz, units<dim::ratio<1l, 1000000l>, dim::meter<1l>, dim::second<-2l> > > >�
compilation terminated due to -fmax-errors=2.
Reply all
Reply to author
Forward
0 new messages