[QUEUED scylla next] utils: big_decimal: change to std::strong_ordering

0 views
Skip to first unread message

Commit Bot

<bot@cloudius-systems.com>
unread,
Jul 29, 2021, 3:44:29 PM7/29/21
to scylladb-dev@googlegroups.com, Avi Kivity
From: Avi Kivity <a...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: next

utils: big_decimal: change to std::strong_ordering

Ref #1449.

---
diff --git a/utils/big_decimal.cc b/utils/big_decimal.cc
--- a/utils/big_decimal.cc
+++ b/utils/big_decimal.cc
@@ -148,13 +148,13 @@ sstring big_decimal::to_string() const
return str;
}

-int big_decimal::compare(const big_decimal& other) const
+std::strong_ordering big_decimal::compare(const big_decimal& other) const
{
auto max_scale = std::max(_scale, other._scale);
boost::multiprecision::cpp_int rescale(10);
boost::multiprecision::cpp_int x = _unscaled_value * boost::multiprecision::pow(rescale, max_scale - _scale);
boost::multiprecision::cpp_int y = other._unscaled_value * boost::multiprecision::pow(rescale, max_scale - other._scale);
- return x == y ? 0 : x < y ? -1 : 1;
+ return x == y ? std::strong_ordering::equal : x < y ? std::strong_ordering::less : std::strong_ordering::greater;
}

big_decimal& big_decimal::operator+=(const big_decimal& other)
diff --git a/utils/big_decimal.hh b/utils/big_decimal.hh
--- a/utils/big_decimal.hh
+++ b/utils/big_decimal.hh
@@ -24,6 +24,7 @@
#include "multiprecision_int.hh"
#include <boost/multiprecision/cpp_int.hpp>
#include <ostream>
+#include <compare>

#include "bytes.hh"

@@ -48,7 +49,7 @@ public:

sstring to_string() const;

- int compare(const big_decimal& other) const;
+ std::strong_ordering compare(const big_decimal& other) const;

big_decimal& operator+=(const big_decimal& other);
big_decimal& operator-=(const big_decimal& other);

Commit Bot

<bot@cloudius-systems.com>
unread,
Jul 29, 2021, 9:40:18 PM7/29/21
to scylladb-dev@googlegroups.com, Avi Kivity
From: Avi Kivity <a...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: master
Reply all
Reply to author
Forward
0 new messages