summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--number.cpp20
-rw-r--r--number.h8
2 files changed, 28 insertions, 0 deletions
diff --git a/number.cpp b/number.cpp
index 75fd0f8..d39ed36 100644
--- a/number.cpp
+++ b/number.cpp
@@ -70,6 +70,26 @@ number::to_uint32() const
return (*this == 0) ? 0 : _operands.front();
}
+std::uint64_t
+number::to_uint64() const
+{
+ auto size = _operands.size();
+
+ if (size > 2) {
+ throw std::out_of_range("> UINT64_MAX");
+ }
+
+ std::uint64_t result = 0;
+
+ for (auto it = _operands.crbegin(); it != _operands.crend(); ++it) {
+ result <<= 32;
+
+ result |= (*it);
+ }
+
+ return result;
+}
+
number::operator bool() const
{
return *this != 0;
diff --git a/number.h b/number.h
index 337a47d..d0d2a10 100644
--- a/number.h
+++ b/number.h
@@ -35,6 +35,14 @@ public:
std::uint32_t to_uint32() const;
/**
+ * \brief Return a 64-bits-wide integer that corresponds to this number.
+ *
+ * \throws std::out_of_range The number cannot be represented by a single
+ * 64-bits-wide integer.
+ */
+ std::uint64_t to_uint64() const;
+
+ /**
* \brief Return true if this number is not equal to 0. Otherwise, return
* false.
*/