summaryrefslogtreecommitdiff
path: root/number.cpp
blob: e942cf207296bfc145a1a95a925b43da72268c4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
}

/* }}} */