Procházet zdrojové kódy

Adding other comparison functions.

Samuel Jaffe před 8 roky
rodič
revize
5573a74602
1 změnil soubory, kde provedl 24 přidání a 1 odebrání
  1. 24 1
      src/biginteger.cpp

+ 24 - 1
src/biginteger.cpp

@@ -288,8 +288,31 @@ bool math::operator==(biginteger const & rhs, biginteger const & lhs) {
   return rhs.is_negative == lhs.is_negative && detail::compare(rhs.data, lhs.data) == 0;
 }
 
-biginteger const biginteger::ZERO{0}, biginteger::ONE{1}, biginteger::NEGATIVE_ONE{-1};
+bool math::operator!=(biginteger const & rhs, biginteger const & lhs) {
+  return !(rhs == lhs);
+}
+
+bool math::operator<=(biginteger const & rhs, biginteger const & lhs) {
+  return !(rhs > lhs);
+}
+
+bool math::operator< (biginteger const & rhs, biginteger const & lhs) {
+  if (rhs.is_negative != lhs.is_negative) { return rhs.is_negative; }
+  else if (rhs.is_negative) { return detail::compare(rhs.data, lhs.data) > 0; }
+  else { return detail::compare(rhs.data, lhs.data) < 0; }
+}
 
+bool math::operator>=(biginteger const & rhs, biginteger const & lhs) {
+  return !(rhs < lhs);
+}
+
+bool math::operator> (biginteger const & rhs, biginteger const & lhs) {
+  if (rhs.is_negative != lhs.is_negative) { return lhs.is_negative; }
+  else if (rhs.is_negative) { return detail::compare(rhs.data, lhs.data) < 0; }
+  else { return detail::compare(rhs.data, lhs.data) > 0; }
+}
+
+biginteger const biginteger::ZERO{0}, biginteger::ONE{1}, biginteger::NEGATIVE_ONE{-1};
 
 std::string biginteger::to_string() const {
   std::vector<char> output(biginteger::SEG_DIGITS * data.size() + 1, '\0');