From 615b8a00aedb3363b4749f706d6df51846b743ac Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sat, 18 Nov 2017 17:21:59 +0100 Subject: Allow conversion of number to 32 bits integer The method to_uint32() converts a number to a 32-bits-wide integer. The function throws if number cannot be represented using only a single 32-bits-wide integer. Signed-off-by: Olivier Gayot --- number.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'number.cpp') 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 {{{ */ -- cgit v1.2.3