From 671f3f8ca44382386daf63c70140742e61200c2e Mon Sep 17 00:00:00 2001
From: Olivier Gayot <og@satcom1.com>
Date: Sat, 26 Aug 2017 00:15:58 +0200
Subject: Added a class "number" with comparison operators

Signed-off-by: Olivier Gayot <og@satcom1.com>
---
 number.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 number.h   | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)
 create mode 100644 number.cpp
 create mode 100644 number.h

diff --git a/number.cpp b/number.cpp
new file mode 100644
index 0000000..e942cf2
--- /dev/null
+++ b/number.cpp
@@ -0,0 +1,58 @@
+#include "number.h"
+
+/* Comparison operators {{{ */
+
+bool
+number::operator<(const number &n) const
+{
+    const auto size = this->_operands.size();
+
+    if (size < n._operands.size()) {
+        return true;
+    }
+
+    if (size > n._operands.size()) {
+        return false;
+    }
+
+    /* Because first item is the least significant. */
+    auto l1(this->_operands);
+    auto l2(n._operands);
+
+    l1.reverse();
+    l2.reverse();
+
+    return l1 < l2;
+}
+
+bool
+number::operator>(const number &n) const
+{
+    return n.operator<(*this);
+}
+
+bool
+number::operator<=(const number &n) const
+{
+    return operator<(n) || operator==(n);
+}
+
+bool
+number::operator>=(const number &n) const
+{
+    return operator>(n) || operator==(n);
+}
+
+bool
+number::operator==(const number &n) const
+{
+    return _operands == n._operands;
+}
+
+bool
+number::operator!=(const number &n) const
+{
+    return _operands != n._operands;
+}
+
+/* }}} */
diff --git a/number.h b/number.h
new file mode 100644
index 0000000..c508a81
--- /dev/null
+++ b/number.h
@@ -0,0 +1,62 @@
+#pragma once
+
+#include <list>
+
+#include <cstdint>
+
+class number {
+public:
+    number() = default;
+
+    /**
+     * \brief Tells whether the number passed as parameter is strictly less
+     * than this number.
+     *
+     * \param n The number to compare with this number.
+     */
+    bool operator<(const number &n) const;
+
+    /**
+     * \brief Tells whether the number passed as parameter is strictly greater
+     * than this number.
+     *
+     * \param n The number to compare with this number.
+     */
+    bool operator>(const number &n) const;
+
+    /**
+     * \brief Tells whether the number passed as parameter is less than or
+     * equal to this number.
+     *
+     * \param n The number to compare with this number.
+     */
+    bool operator<=(const number &n) const;
+
+    /**
+     * \brief Tells whether the number passed as parameter is greater than or
+     * equal to this number.
+     *
+     * \param n The number to compare with this number.
+     */
+    bool operator>=(const number &n) const;
+
+    /**
+     * \brief Tells whether the number passed as parameter is equal to this
+     * number.
+     *
+     * \param n The number to compare with this number.
+     */
+    bool operator==(const number &n) const;
+
+    /**
+     * \brief Tells whether the number passed as parameter is not equal to this
+     * number.
+     *
+     * \param n The number to compare with this number.
+     */
+    bool operator!=(const number &n) const;
+
+private:
+     /* First item is the least significant. */
+    std::list<std::uint64_t> _operands;
+};
-- 
cgit v1.2.3