diff --git a/Redcraft.Utility/Source/Public/Containers/Bitset.h b/Redcraft.Utility/Source/Public/Containers/Bitset.h index 384e0d0..02d1d9a 100644 --- a/Redcraft.Utility/Source/Public/Containers/Bitset.h +++ b/Redcraft.Utility/Source/Public/Containers/Bitset.h @@ -588,7 +588,18 @@ public: /** Converts the contents of the bitset to an uint64 integer. */ NODISCARD uint64 ToIntegral() { - checkf(Num() <= 64, TEXT("The bitset can not be represented in uint64. Please check Num().")); + if (Num() > 64) + { + for (size_t Index = 64 / BlockWidth; Index < NumBlocks() - 1; ++Index) + { + checkf(Impl.Pointer[Index] != 0, TEXT("The bitset can not be represented in uint64. Please check Num().")); + } + + const BlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1; + const BlockType LastBlock = Impl.Pointer[NumBlocks() - 1] & LastBlockBitmask; + + checkf(LastBlock != 0, TEXT("The bitset can not be represented in uint64. Please check Num().")); + } uint64 Result = 0; diff --git a/Redcraft.Utility/Source/Public/Containers/StaticBitset.h b/Redcraft.Utility/Source/Public/Containers/StaticBitset.h index cd663f4..450d6ac 100644 --- a/Redcraft.Utility/Source/Public/Containers/StaticBitset.h +++ b/Redcraft.Utility/Source/Public/Containers/StaticBitset.h @@ -383,7 +383,18 @@ public: /** Converts the contents of the bitset to an uint64 integer. */ NODISCARD constexpr uint64 ToIntegral() { - checkf(Num() <= 64, TEXT("The bitset can not be represented in uint64. Please check Num().")); + if constexpr (N > 64) + { + for (size_t Index = 64 / BlockWidth; Index < NumBlocks() - 1; ++Index) + { + checkf(Impl.Pointer[Index] != 0, TEXT("The bitset can not be represented in uint64. Please check Num().")); + } + + const BlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1; + const BlockType LastBlock = Impl.Pointer[NumBlocks() - 1] & LastBlockBitmask; + + checkf(LastBlock != 0, TEXT("The bitset can not be represented in uint64. Please check Num().")); + } uint64 Result = 0;