Skip to content

Commit

Permalink
compiler fixes for gcc/clang
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Nov 11, 2024
1 parent 54b8bd6 commit a3f8228
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
16 changes: 8 additions & 8 deletions include/universal/number/efloat/efloat_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,20 +322,20 @@ class efloat {
private:

// efloat - efloat logic comparisons
template<unsigned nlimbs>
friend bool operator==(const efloat<nlimbs>& lhs, const efloat<nlimbs>& rhs);
template<unsigned nnlimbs>
friend bool operator==(const efloat<nnlimbs>& lhs, const efloat<nnlimbs>& rhs);

// efloat - literal logic comparisons
template<unsigned nlimbs>
friend bool operator==(const efloat<nlimbs>& lhs, long long rhs);
template<unsigned nnlimbs>
friend bool operator==(const efloat<nnlimbs>& lhs, long long rhs);

// literal - efloat logic comparisons
template<unsigned nlimbs>
friend bool operator==(long long lhs, const efloat<nlimbs>& rhs);
template<unsigned nnlimbs>
friend bool operator==(long long lhs, const efloat<nnlimbs>& rhs);

// find the most significant bit set
template<unsigned nlimbs>
friend signed findMsb(const efloat<nlimbs>& v);
template<unsigned nnlimbs>
friend signed findMsb(const efloat<nnlimbs>& v);
};

////////////////////////////////////////////////////////////////////////////////
Expand Down
38 changes: 18 additions & 20 deletions include/universal/number/rational/rational_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ class rational {

// in-place arithmetic assignment operators
rational& operator+=(const rational& rhs) {
bool lhsSign = sign();
bool rhsSign = rhs.sign();
SignedBlockBinary x = n;
SignedBlockBinary y = d;
SignedBlockBinary v = rhs.n;
Expand All @@ -189,7 +187,7 @@ class rational {
}
rational& operator+=(double rhs) { return *this += rational(rhs); }
rational& operator-=(const rational& rhs) {
bool rhsSign = rhs.sign();

normalize();
return *this;
}
Expand Down Expand Up @@ -360,40 +358,40 @@ class rational {
SignedBlockBinary d; // denominator, always positive so that sign of numerator is sign of rational

// template parameters need names different from class template parameters (for gcc and clang)
template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
friend std::ostream& operator<< (std::ostream& ostr, const rational<nnbits,nbt>& r);
template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
friend std::istream& operator>> (std::istream& istr, rational<nnbits,nbt>& r);

template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
friend bool operator==(const rational<nnbits,nbt>& lhs, const rational<nnbits,nbt>& rhs);
template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
friend bool operator!=(const rational<nnbits,nbt>& lhs, const rational<nnbits,nbt>& rhs);
template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
friend bool operator< (const rational<nnbits,nbt>& lhs, const rational<nnbits,nbt>& rhs);
template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
friend bool operator> (const rational<nnbits,nbt>& lhs, const rational<nnbits,nbt>& rhs);
template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
friend bool operator<=(const rational<nnbits,nbt>& lhs, const rational<nnbits,nbt>& rhs);
template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
friend bool operator>=(const rational<nnbits,nbt>& lhs, const rational<nnbits,nbt>& rhs);
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////
/// stream opreators

template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
inline std::ostream& operator<<(std::ostream& ostr, const rational<nnbits,nbt>& v) {
return ostr << double(v);
}

template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
inline std::istream& operator>>(std::istream& istr, const rational<nnbits,nbt>& v) {
istr >> v._fraction;
return istr;
}

template<size_t nbits, typename bt>
template<unsigned nbits, typename bt>
inline std::string to_binary(const rational<nbits,bt>& v, bool nibbleMarker = true) {
std::stringstream s;
s << to_binary(v.numerator(), nibbleMarker)
Expand All @@ -405,17 +403,17 @@ inline std::string to_binary(const rational<nbits,bt>& v, bool nibbleMarker = tr
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/// binary logic functions

template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
inline bool operator==(const rational<nnbits,nbt>& lhs, const rational<nnbits,nbt>& rhs) { return false; }
template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
inline bool operator!=(const rational<nnbits,nbt>& lhs, const rational<nnbits,nbt>& rhs) { return !operator==(lhs, rhs); }
template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
inline bool operator< (const rational<nnbits,nbt>& lhs, const rational<nnbits,nbt>& rhs) { return false; }
template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
inline bool operator> (const rational<nnbits,nbt>& lhs, const rational<nnbits,nbt>& rhs) { return operator< (rhs, lhs); }
template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
inline bool operator<=(const rational<nnbits,nbt>& lhs, const rational<nnbits,nbt>& rhs) { return !operator> (lhs, rhs); }
template<size_t nnbits, typename nbt>
template<unsigned nnbits, typename nbt>
inline bool operator>=(const rational<nnbits,nbt>& lhs, const rational<nnbits,nbt>& rhs) { return !operator< (lhs, rhs); }

/////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 6 additions & 1 deletion static/rational/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ try {
using Real = rational<16,uint16_t>;

Real a(1.0f), b(0.5f);
ArithmeticOperators(a, b);
std::cout << a << '\n';
std::cout << to_binary(a) << '\n';
using SignedBlockBinary = blockbinary<16, uint16_t>;
SignedBlockBinary sbb = 17;
std::cout << double(sbb) << '\n';
//ArithmeticOperators(a, b);
}

// report on the dynamic range of some standard configurations
Expand Down

0 comments on commit a3f8228

Please sign in to comment.