summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--number.cpp10
-rw-r--r--number.h8
2 files changed, 18 insertions, 0 deletions
diff --git a/number.cpp b/number.cpp
index fcc6dc0..ae4b167 100644
--- a/number.cpp
+++ b/number.cpp
@@ -51,6 +51,16 @@ number::to_dec_string() const
return ss.str();
}
+std::uint32_t
+number::to_uint32() const
+{
+ if (*this > UINT32_MAX) {
+ throw std::out_of_range("> UINT32_MAX");
+ }
+
+ return (*this == 0) ? 0 : _operands.front();
+}
+
/* }}} */
/* Operations {{{ */
diff --git a/number.h b/number.h
index 189011d..d93ed70 100644
--- a/number.h
+++ b/number.h
@@ -26,6 +26,14 @@ public:
std::string to_dec_string() const;
/**
+ * \brief Return a 32-bits-wide integer that corresponds to this number.
+ *
+ * \throws std::out_of_range The number cannot be represented by a single
+ * 32-bits-wide integer.
+ */
+ std::uint32_t to_uint32() const;
+
+ /**
* \brief Return the result of the addition of a number and this number.
*
* \param n The number to add to this number.