uint128: Make to_integer(), to_uint64() assert magnitude
- All places these are used already handle magnitude checks correctly - As a "bit-twiddling" method, low_bits() truncates - As a "semantics preserving type conversion" method, to_uint64() asserts - Add low_32_bits() as a "bit-twiddling" non-asserting to_integer() equivalent
This commit is contained in:
parent
4b8c211629
commit
27e224b012
1 changed files with 15 additions and 2 deletions
|
|
@ -3,6 +3,8 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <fc/exception/exception.hpp>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning (push)
|
#pragma warning (push)
|
||||||
#pragma warning (disable : 4244)
|
#pragma warning (disable : 4244)
|
||||||
|
|
@ -74,8 +76,19 @@ namespace fc
|
||||||
friend bool operator >= ( const uint128& l, const uint128& r ) { return l == r || l > r; }
|
friend bool operator >= ( const uint128& l, const uint128& r ) { return l == r || l > r; }
|
||||||
friend bool operator <= ( const uint128& l, const uint128& r ) { return l == r || l < r; }
|
friend bool operator <= ( const uint128& l, const uint128& r ) { return l == r || l < r; }
|
||||||
|
|
||||||
uint32_t to_integer()const { return (uint32_t)lo; }
|
uint32_t to_integer()const
|
||||||
uint64_t to_uint64()const { return lo; }
|
{
|
||||||
|
FC_ASSERT( hi == 0 );
|
||||||
|
uint32_t lo32 = (uint32_t) lo;
|
||||||
|
FC_ASSERT( lo == lo32 );
|
||||||
|
return lo32;
|
||||||
|
}
|
||||||
|
uint64_t to_uint64()const
|
||||||
|
{
|
||||||
|
FC_ASSERT( hi == 0 );
|
||||||
|
return lo;
|
||||||
|
}
|
||||||
|
uint32_t low_32_bits()const { return (uint32_t) lo; }
|
||||||
uint64_t low_bits()const { return lo; }
|
uint64_t low_bits()const { return lo; }
|
||||||
uint64_t high_bits()const { return hi; }
|
uint64_t high_bits()const { return hi; }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue