Skip to content

Commit

Permalink
Fixed "-0" bug for string constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
SomedudeX committed May 8, 2024
1 parent 24a45a7 commit c93a1ec
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/variable_int/constructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ namespace vint {
}

Int::Int(const std::string& number) {
if (number.empty())
m_storage = { 0 };
if (number == "-0")
m_storage = { 0 };
if (number[0] == '-')
m_sign = sign::negative;

size_t num_start = (m_sign == sign::negative) ? 1 : 0;
std::vector<uint8_t> num_vec(number.size());
for (size_t i = num_start; i < num_vec.size(); i++)
num_vec[i] = number[i] - '0';
std::vector<uint8_t> num_vec(number.size() - num_start);
for (size_t i = num_start; i < number.size(); i++)
num_vec[i - num_start] = number[i] - '0';

while (!num_vec.empty()) {
m_storage.push_back(divide_vectors(num_vec, (uint64_t) (UINT32_MAX) + 1));
}
Expand Down

0 comments on commit c93a1ec

Please sign in to comment.