Skip to content

Commit

Permalink
WIP: changing literal arguments to rely on implicit double conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Sep 16, 2024
1 parent 20ee257 commit 90d01dd
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions include/universal/number/efloat/efloat_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class efloat {
explicit operator double() const noexcept { return convert_to_ieee754<double>(); }

#if LONG_DOUBLE_SUPPORT
constexpr efloat(long double iv) noexcept : _bits{} { *this = iv; }
constexpr efloat(long double iv) noexcept { *this = iv; }
BIT_CAST_CONSTEXPR efloat& operator=(long double rhs) noexcept { return convert_ieee754(rhs); }
explicit operator long double() const noexcept { return convert_to_ieee754<long double>(); }
#endif
Expand All @@ -97,15 +97,27 @@ class efloat {
efloat& operator+=(const efloat& rhs) {
return *this;
}
efloat& operator+=(double rhs) {
return *this;
}
efloat& operator-=(const efloat& rhs) {
return *this;
}
efloat& operator-=(double rhs) {
return *this;
}
efloat& operator*=(const efloat& rhs) {
return *this;
}
efloat& operator*=(double rhs) {
return *this;
}
efloat& operator/=(const efloat& rhs) {
return *this;
}
efloat& operator/=(double rhs) {
return *this;
}

// modifiers
inline void clear() { sign = false; exp = 0; limb.clear(); }
Expand Down Expand Up @@ -250,7 +262,7 @@ inline std::ostream& operator<<(std::ostream& ostr, const efloat& i) {
std::ios_base::fmtflags ff;
ff = ostr.flags();
ss.flags(ff);
// ss << std::setw(width) << std::setprecision(prec) << i.str(size_t(prec));
ss << std::setw(width) << std::setprecision(prec) << "TBD";

return ostr << ss.str();
}
Expand Down Expand Up @@ -302,27 +314,27 @@ inline bool operator>=(const efloat& lhs, const efloat& rhs) {
// efloat - literal binary logic operators
// equal: precondition is that the byte-storage is properly nulled in all arithmetic paths

inline bool operator==(const efloat& lhs, const long long rhs) {
inline bool operator==(const efloat& lhs, double rhs) {
return operator==(lhs, efloat(rhs));
}

inline bool operator!=(const efloat& lhs, const long long rhs) {
inline bool operator!=(const efloat& lhs, double rhs) {
return !operator==(lhs, rhs);
}

inline bool operator< (const efloat& lhs, const long long rhs) {
inline bool operator< (const efloat& lhs, double rhs) {
return operator<(lhs, efloat(rhs));
}

inline bool operator> (const efloat& lhs, const long long rhs) {
inline bool operator> (const efloat& lhs, double rhs) {
return operator< (efloat(rhs), lhs);
}

inline bool operator<=(const efloat& lhs, const long long rhs) {
inline bool operator<=(const efloat& lhs, double rhs) {
return operator< (lhs, rhs) || operator==(lhs, rhs);
}

inline bool operator>=(const efloat& lhs, const long long rhs) {
inline bool operator>=(const efloat& lhs, double rhs) {
return !operator< (lhs, rhs);
}

Expand All @@ -331,27 +343,27 @@ inline bool operator>=(const efloat& lhs, const long long rhs) {
// precondition is that the byte-storage is properly nulled in all arithmetic paths


inline bool operator==(const long long lhs, const efloat& rhs) {
inline bool operator==(double lhs, const efloat& rhs) {
return operator==(efloat(lhs), rhs);
}

inline bool operator!=(const long long lhs, const efloat& rhs) {
inline bool operator!=(double lhs, const efloat& rhs) {
return !operator==(lhs, rhs);
}

inline bool operator< (const long long lhs, const efloat& rhs) {
inline bool operator< (double lhs, const efloat& rhs) {
return operator<(efloat(lhs), rhs);
}

inline bool operator> (const long long lhs, const efloat& rhs) {
inline bool operator> (double lhs, const efloat& rhs) {
return operator< (rhs, lhs);
}

inline bool operator<=(const long long lhs, const efloat& rhs) {
inline bool operator<=(double lhs, const efloat& rhs) {
return operator< (lhs, rhs) || operator==(lhs, rhs);
}

inline bool operator>=(const long long lhs, const efloat& rhs) {
inline bool operator>=(double lhs, const efloat& rhs) {
return !operator< (lhs, rhs);
}

Expand Down Expand Up @@ -392,45 +404,45 @@ inline efloat operator/(const efloat& lhs, const efloat& rhs) {
// efloat - literal binary arithmetic operators
// BINARY ADDITION

inline efloat operator+(const efloat& lhs, const long long rhs) {
inline efloat operator+(const efloat& lhs, double rhs) {
return operator+(lhs, efloat(rhs));
}
// BINARY SUBTRACTION

inline efloat operator-(const efloat& lhs, const long long rhs) {
inline efloat operator-(const efloat& lhs, double rhs) {
return operator-(lhs, efloat(rhs));
}
// BINARY MULTIPLICATION

inline efloat operator*(const efloat& lhs, const long long rhs) {
inline efloat operator*(const efloat& lhs, double rhs) {
return operator*(lhs, efloat(rhs));
}
// BINARY DIVISION

inline efloat operator/(const efloat& lhs, const long long rhs) {
inline efloat operator/(const efloat& lhs, double rhs) {
return operator/(lhs, efloat(rhs));
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
// literal - efloat binary arithmetic operators
// BINARY ADDITION

inline efloat operator+(const long long lhs, const efloat& rhs) {
inline efloat operator+(double lhs, const efloat& rhs) {
return operator+(efloat(lhs), rhs);
}
// BINARY SUBTRACTION

inline efloat operator-(const long long lhs, const efloat& rhs) {
inline efloat operator-(double lhs, const efloat& rhs) {
return operator-(efloat(lhs), rhs);
}
// BINARY MULTIPLICATION

inline efloat operator*(const long long lhs, const efloat& rhs) {
inline efloat operator*(double lhs, const efloat& rhs) {
return operator*(efloat(lhs), rhs);
}
// BINARY DIVISION

inline efloat operator/(const long long lhs, const efloat& rhs) {
inline efloat operator/(double lhs, const efloat& rhs) {
return operator/(efloat(lhs), rhs);
}

Expand Down

0 comments on commit 90d01dd

Please sign in to comment.