mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
Added to_ulong() and to_ullong()
This commit is contained in:
parent
5e78b48b6c
commit
51b10c498c
@ -497,7 +497,7 @@ namespace etl
|
||||
{
|
||||
typedef typename etl::make_unsigned<T>::type unsigned_t;
|
||||
|
||||
const unsigned_t Mask = etl::make_lsb_mask<unsigned_t>(Length);
|
||||
const unsigned_t Mask = etl::make_lsb_mask<unsigned_t>(Length);
|
||||
const unsigned_t Shift = Position % Bits_Per_Element;
|
||||
|
||||
unsigned_t value = static_cast<unsigned_t>(*pbuffer >> Shift) & Mask;
|
||||
@ -1780,10 +1780,17 @@ namespace etl
|
||||
const size_t Shift = etl::integral_limits<element_type>::bits;
|
||||
|
||||
// Set the non-zero elements.
|
||||
while ((value != 0) && (i != number_of_elements))
|
||||
if ETL_IF_CONSTEXPR(etl::integral_limits<element_type>::bits == etl::integral_limits<unsigned long long>::bits)
|
||||
{
|
||||
pbuffer[i++] = value & All_Set_Element;
|
||||
value = value >> Shift;
|
||||
pbuffer[i++] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((value != 0) && (i != number_of_elements))
|
||||
{
|
||||
pbuffer[i++] = value & All_Set_Element;
|
||||
value = value >> Shift;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the remaining elements.
|
||||
@ -2267,9 +2274,9 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Get as an unsigned long.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14 unsigned long to_ulong() const ETL_NOEXCEPT
|
||||
unsigned long to_ulong() const
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::integral_limits<unsigned long>::bits >= Active_Bits, "to_ulong() : Active_Bits > unsigned long");
|
||||
ETL_ASSERT(etl::integral_limits<unsigned long>::bits >= Active_Bits, ETL_ERROR(etl::bitset_overflow));
|
||||
|
||||
return implementation::template value<unsigned long>(buffer, Number_Of_Elements);
|
||||
}
|
||||
@ -2277,9 +2284,9 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Get as an unsigned long long.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14 unsigned long long to_ullong() const ETL_NOEXCEPT
|
||||
unsigned long long to_ullong() const
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::integral_limits<unsigned long long>::bits >= Active_Bits, "to_ullong() : Active_Bits > unsigned long long");
|
||||
ETL_ASSERT(etl::integral_limits<unsigned long long>::bits >= Active_Bits, ETL_ERROR(etl::bitset_overflow));
|
||||
|
||||
return implementation::template value<unsigned long long>(buffer, Number_Of_Elements);
|
||||
}
|
||||
@ -3264,9 +3271,9 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Get as an unsigned long.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14 unsigned long to_ulong() const ETL_NOEXCEPT
|
||||
unsigned long to_ulong() const
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::integral_limits<unsigned long>::bits >= Active_Bits, "Active_Bits > unsigned long");
|
||||
ETL_ASSERT(etl::integral_limits<unsigned long>::bits >= Active_Bits, ETL_ERROR(etl::bitset_overflow));
|
||||
|
||||
return implementation::template value<unsigned long>(pbuffer, Number_Of_Elements);
|
||||
}
|
||||
@ -3274,9 +3281,9 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Get as an unsigned long long.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14 unsigned long long to_ullong() const ETL_NOEXCEPT
|
||||
unsigned long long to_ullong() const
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::integral_limits<unsigned long long>::bits >= Active_Bits, "Active_Bits > unsigned long long");
|
||||
ETL_ASSERT(etl::integral_limits<unsigned long long>::bits >= Active_Bits, ETL_ERROR(etl::bitset_overflow));
|
||||
|
||||
return implementation::template value<unsigned long long>(pbuffer, Number_Of_Elements);
|
||||
}
|
||||
|
||||
@ -1140,6 +1140,56 @@ namespace
|
||||
CHECK_EQUAL(std::numeric_limits<int64_t>::max(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ulong_min)
|
||||
{
|
||||
ETL_CONSTEXPR14 etl::bitset<etl::integral_limits<unsigned long>::bits> data((unsigned long)etl::integral_limits<unsigned long>::min);
|
||||
unsigned long value = data.to_ulong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::min(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ulong_max)
|
||||
{
|
||||
ETL_CONSTEXPR14 etl::bitset<etl::integral_limits<unsigned long>::bits> data((unsigned long)etl::integral_limits<unsigned long>::max);
|
||||
unsigned long value = data.to_ulong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::max(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ulong_overflow)
|
||||
{
|
||||
ETL_CONSTEXPR14 etl::bitset<etl::integral_limits<unsigned long>::bits + 1> data((unsigned long)etl::integral_limits<unsigned long>::min);
|
||||
CHECK_THROW(data.to_ulong(), etl::bitset_overflow);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ullong_min)
|
||||
{
|
||||
ETL_CONSTEXPR14 etl::bitset<etl::integral_limits<unsigned long long>::bits> data((unsigned long long)etl::integral_limits<unsigned long long>::min);
|
||||
unsigned long long value = data.to_ullong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::min(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ullong_max)
|
||||
{
|
||||
ETL_CONSTEXPR14 etl::bitset<etl::integral_limits<unsigned long long>::bits> data((unsigned long long)etl::integral_limits<unsigned long long>::max);
|
||||
unsigned long long value = data.to_ullong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long long>::max(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ullong_overflow)
|
||||
{
|
||||
ETL_CONSTEXPR14 etl::bitset<etl::integral_limits<unsigned long long>::bits + 1> data((unsigned long long)etl::integral_limits<unsigned long long>::min);
|
||||
CHECK_THROW(data.to_ullong(), etl::bitset_overflow);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_position_set)
|
||||
{
|
||||
|
||||
@ -1136,6 +1136,56 @@ namespace
|
||||
CHECK_EQUAL(std::numeric_limits<int64_t>::max(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ulong_min)
|
||||
{
|
||||
ETL_CONSTEXPR14 etl::bitset<etl::integral_limits<unsigned long>::bits, uint64_t> data((unsigned long)etl::integral_limits<unsigned long>::min);
|
||||
unsigned long value = data.to_ulong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::min(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ulong_max)
|
||||
{
|
||||
ETL_CONSTEXPR14 etl::bitset<etl::integral_limits<unsigned long>::bits, uint64_t> data((unsigned long)etl::integral_limits<unsigned long>::max);
|
||||
unsigned long value = data.to_ulong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::max(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ulong_overflow)
|
||||
{
|
||||
ETL_CONSTEXPR14 etl::bitset<etl::integral_limits<unsigned long>::bits + 1, uint64_t> data((unsigned long)etl::integral_limits<unsigned long>::min);
|
||||
CHECK_THROW(data.to_ulong(), etl::bitset_overflow);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ullong_min)
|
||||
{
|
||||
ETL_CONSTEXPR14 etl::bitset<etl::integral_limits<unsigned long long>::bits, uint64_t> data((unsigned long long)etl::integral_limits<unsigned long long>::min);
|
||||
unsigned long long value = data.to_ullong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::min(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ullong_max)
|
||||
{
|
||||
ETL_CONSTEXPR14 etl::bitset<etl::integral_limits<unsigned long long>::bits, uint64_t> data((unsigned long long)etl::integral_limits<unsigned long long>::max);
|
||||
unsigned long long value = data.to_ullong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long long>::max(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ullong_overflow)
|
||||
{
|
||||
ETL_CONSTEXPR14 etl::bitset<etl::integral_limits<unsigned long long>::bits + 1, uint64_t> data((unsigned long long)etl::integral_limits<unsigned long long>::min);
|
||||
CHECK_THROW(data.to_ullong(), etl::bitset_overflow);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_position_set)
|
||||
{
|
||||
|
||||
@ -1082,6 +1082,62 @@ namespace
|
||||
CHECK_EQUAL(std::numeric_limits<uint64_t>::max(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ulong_min)
|
||||
{
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long>::bits>::buffer_type buffer;
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long>::bits> data((unsigned long)etl::integral_limits<unsigned long>::min, buffer);
|
||||
unsigned long value = data.to_ulong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::min(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ulong_max)
|
||||
{
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long>::bits>::buffer_type buffer;
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long>::bits> data((unsigned long)etl::integral_limits<unsigned long>::max, buffer);
|
||||
unsigned long value = data.to_ulong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::max(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ulong_overflow)
|
||||
{
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long>::bits + 1>::buffer_type buffer;
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long>::bits + 1> data((unsigned long)etl::integral_limits<unsigned long>::min, buffer);
|
||||
CHECK_THROW(data.to_ulong(), etl::bitset_overflow);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ullong_min)
|
||||
{
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long long>::bits>::buffer_type buffer;
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long long>::bits> data((unsigned long long)etl::integral_limits<unsigned long long>::min, buffer);
|
||||
unsigned long long value = data.to_ullong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::min(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ullong_max)
|
||||
{
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long long>::bits>::buffer_type buffer;
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long long>::bits> data((unsigned long long)etl::integral_limits<unsigned long long>::max, buffer);
|
||||
unsigned long long value = data.to_ullong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long long>::max(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ullong_overflow)
|
||||
{
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long long>::bits + 1>::buffer_type buffer;
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long long>::bits + 1> data((unsigned long long)etl::integral_limits<unsigned long long>::min, buffer);
|
||||
CHECK_THROW(data.to_ullong(), etl::bitset_overflow);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_position_set)
|
||||
{
|
||||
|
||||
@ -1110,6 +1110,63 @@ namespace
|
||||
CHECK_EQUAL(std::numeric_limits<uint64_t>::max(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ulong_min)
|
||||
{
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long>::bits, uint64_t>::buffer_type buffer;
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long>::bits, uint64_t> data((unsigned long)etl::integral_limits<unsigned long>::min, buffer);
|
||||
unsigned long value = data.to_ulong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::min(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ulong_max)
|
||||
{
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long>::bits, uint64_t>::buffer_type buffer;
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long>::bits, uint64_t> data((unsigned long)etl::integral_limits<unsigned long>::max, buffer);
|
||||
unsigned long value = data.to_ulong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::max(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ulong_overflow)
|
||||
{
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long>::bits + 1, uint64_t>::buffer_type buffer;
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long>::bits + 1, uint64_t> data((unsigned long)etl::integral_limits<unsigned long>::min, buffer);
|
||||
CHECK_THROW(data.to_ulong(), etl::bitset_overflow);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ullong_min)
|
||||
{
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long long>::bits, uint64_t>::buffer_type buffer;
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long long>::bits, uint64_t> data((unsigned long long)etl::integral_limits<unsigned long long>::min, buffer);
|
||||
unsigned long long value = data.to_ullong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::min(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ullong_max)
|
||||
{
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long long>::bits, uint64_t>::buffer_type buffer;
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long long>::bits, uint64_t> data((unsigned long long)etl::integral_limits<unsigned long long>::max, buffer);
|
||||
unsigned long long value = data.to_ullong();
|
||||
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long long>::max(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_to_ullong_overflow)
|
||||
{
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long long>::bits + 1, uint64_t>::buffer_type buffer;
|
||||
etl::bitset_ext<etl::integral_limits<unsigned long long>::bits + 1, uint64_t> data((unsigned long long)etl::integral_limits<unsigned long long>::min, buffer);
|
||||
|
||||
CHECK_THROW(data.to_ullong(), etl::bitset_overflow);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_position_set)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user