Skip to content

Commit

Permalink
bigint test
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Dec 18, 2023
1 parent 27366ba commit a28a1aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions include/jsoncons/bigint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace detail {
using stored_allocator_type = allocator_type;
using pointer = typename allocator_traits_type::pointer;
using value_type = typename allocator_traits_type::value_type;
using size_type = typename allocator_traits_type::size_type;
using size_type = std::size_t;
using pointer_traits = std::pointer_traits<pointer>;

basic_bigint_base()
Expand Down Expand Up @@ -210,7 +210,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
data_(nullptr)
{
create(stor.length_, alloc);
std::memcpy(data_, stor.data_, stor.length_*sizeof(uint64_t));
std::memcpy(data_, stor.data_, size_type(stor.length_*sizeof(uint64_t)));
}

dynamic_storage(dynamic_storage&& stor) noexcept
Expand Down Expand Up @@ -260,7 +260,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
data_ = std::allocator_traits<real_allocator_type>::allocate(alloc, capacity_new);
if (length_ > 0)
{
std::memcpy( data_, data_old, length_*sizeof(uint64_t));
std::memcpy( data_, data_old, size_type(length_*sizeof(uint64_t)));
}
if (capacity_ > 0 && data_ != nullptr)
{
Expand Down Expand Up @@ -563,7 +563,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
common_stor_.is_negative_ = y.is_negative();
if ( y.length() > 0 )
{
std::memcpy( data(), y.data(), y.length()*sizeof(uint64_t) );
std::memcpy( data(), y.data(), size_type(y.length()*sizeof(uint64_t)) );
}
}
return *this;
Expand Down Expand Up @@ -877,7 +877,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>

if ( old_length > length() )
{
memset( data() + length(), 0, size_type(old_length - length())*sizeof(uint64_t) );
memset( data() + length(), 0, size_type(old_length - length()*sizeof(uint64_t)) );
}

reduce();
Expand Down
10 changes: 10 additions & 0 deletions test/corelib/src/bigint_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,5 +369,15 @@ TEST_CASE("bigint operations")

CHECK(a == b);
}

SECTION("|=")
{
bigint a{0};
bigint b = bigint::from_string("1277902648419017187919156692641295109476255233737630537760832794503886212911067061184379695097643279217271150419129022856601771338794256383410400076210073482253089544155377");
bigint expected = b;
b |= a;

CHECK(expected == b);
}
}

0 comments on commit a28a1aa

Please sign in to comment.