C++ Does operator< depend on any other user-defined functions? If so, which ones
ID: 3927945 • Letter: C
Question
C++
Does operator< depend on any other user-defined functions? If so, which ones?
bool vnl_decnum::operator< (vnl_decnum const& r) const
{
#ifdef DEBUG
std::cerr << "Entering vnl_decnum::operator< with " << data_ << " and " << r.data() << ' ';
#endif
std::string rs = r.data();
if (data_ == "NaN" || rs == "NaN") return false; // NaN compares to nothing!
else if (operator==(r)) return false;
else if (data_ == "Inf") return sign_ == '-';
else if (rs == "Inf") return r.sign() == '+';
if (sign_=='-' && r.sign() == '-') return -r < operator-();
else if (sign_=='-') return true;
else if (r.sign() == '-') return false;
else if (sign_==' ') return true;
else if (r.sign() == ' ') return false;
else if (data_.length()+exp_ < rs.length()+r.exp()) return true;
else if (data_.length()+exp_ > rs.length()+r.exp()) return false;
else // at this point, the orders of magnitude are the same
return comp(data_,rs);
}
bool vnl_decnum::operator< (vnl_decnum const& r) const
{
#ifdef DEBUG
std::cerr << "Entering vnl_decnum::operator< with " << data_ << " and " << r.data() << ' ';
#endif
std::string rs = r.data();
if (data_ == "NaN" || rs == "NaN") return false; // NaN compares to nothing!
else if (operator==(r)) return false;
else if (data_ == "Inf") return sign_ == '-';
else if (rs == "Inf") return r.sign() == '+';
if (sign_=='-' && r.sign() == '-') return -r < operator-();
else if (sign_=='-') return true;
else if (r.sign() == '-') return false;
else if (sign_==' ') return true;
else if (r.sign() == ' ') return false;
else if (data_.length()+exp_ < rs.length()+r.exp()) return true;
else if (data_.length()+exp_ > rs.length()+r.exp()) return false;
else // at this point, the orders of magnitude are the same
return comp(data_,rs);
}
Explanation / Answer
< symbols depend on
1)length() and
2)exp() functions
comparison is done between these functions
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.