Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BigNumber::BigNumber(std::string input) { //Remember to check if all literals are not digits!
- uint32_t input_len = input.size();
- if (input_len == 0) {
- throw "String used for class instance construction must not be empty.";
- }
- if (input_len == 1 && input[0] == 0) {
- this->size = 0;
- return;
- }
- uint32_t current_alloc_size = BigNumber::ALLOC_SIZE;
- uint32_t start, len, current_bit;
- start = this->is_negative = input[0] == '-';
- len = current_bit = 0;
- this->blocks.push_back(*create_new_block(current_alloc_size)); //Here we create and add empty block to the list.
- Block *current_block = &this->blocks.back(); //Points to created element on the list.
- int64_t *current_elements = current_block->get_bits_array();
- int64_t current_element = 0;
- uint32_t BITS_PER_ELEMENT = sizeof(uint64_t) * Architecture::PlatformChecks::bits_per_byte(); // should move to header
- while (start < input_len - 1 || input[input_len - 1] != '0') {
- if (current_bit == BITS_PER_ELEMENT) {
- current_bit = 0;
- ++current_element;
- ++len;
- if (current_element == current_alloc_size) {
- current_alloc_size = current_alloc_size << 1;
- this->blocks.push_back(*create_new_block(current_alloc_size)); //Here we create and add empty block to the list.
- Block *current_block = &this->blocks.back(); //Points to created element on the list.
- current_elements = current_block->get_bits_array();
- current_element = 0;
- }
- }
- current_elements[current_element] += ((input[input_len - 1] & 1) << current_bit);
- int tmp = ((input[input_len - 1] & 1) << current_bit); // for debug purposes
- for (int32_t i = start; i < input_len; ++i) {
- if (i < input_len - 1)
- input[i + 1] += 10 * (input[i] & 1);
- input[i] = (input[i] - '0' >> 1) + '0';
- }
- if (input[start] == '0')
- ++start;
- ++current_bit;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement