Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::HugeintCastToBignum Struct Reference

--------------------------------— (u)HugeInt Cast --------------------------------— // More...

Public Member Functions

template<>
bignum_t Operation (uhugeint_t int_value, Vector &result)
template<>
bignum_t Operation (hugeint_t int_value, Vector &result)

Static Public Member Functions

template<class SRC>
static bignum_t Operation (SRC input, Vector &result)

Detailed Description

--------------------------------— (u)HugeInt Cast --------------------------------— //

Member Function Documentation

◆ Operation() [1/3]

template<class SRC>
bignum_t duckdb::HugeintCastToBignum::Operation ( SRC input,
Vector & result )
inlinestatic
46599 {
46600 throw InternalException("Unsupported type for cast to BIGNUM");
46601 }

◆ Operation() [2/3]

template<>
bignum_t duckdb::HugeintCastToBignum::Operation ( uhugeint_t int_value,
Vector & result )
212643 {
212644 uint32_t data_byte_size;
212645 if (int_value.upper != NumericLimits<uint64_t>::Maximum()) {
212646 data_byte_size =
212647 (int_value.upper == 0) ? 0 : static_cast<uint32_t>(std::ceil(std::log2(int_value.upper + 1) / 8.0));
212648 } else {
212649 data_byte_size = static_cast<uint32_t>(std::ceil(std::log2(int_value.upper) / 8.0));
212650 }
212651
212652 uint32_t upper_byte_size = data_byte_size;
212653 if (data_byte_size > 0) {
212654 // If we have at least one byte on the upper side, the bottom side is complete
212655 data_byte_size += 8;
212656 } else {
212657 if (int_value.lower != NumericLimits<uint64_t>::Maximum()) {
212658 data_byte_size += static_cast<uint32_t>(std::ceil(std::log2(int_value.lower + 1) / 8.0));
212659 } else {
212660 data_byte_size += static_cast<uint32_t>(std::ceil(std::log2(int_value.lower) / 8.0));
212661 }
212662 }
212663 if (data_byte_size == 0) {
212664 data_byte_size++;
212665 }
212666 uint32_t blob_size = data_byte_size + Bignum::BIGNUM_HEADER_SIZE;
212667 auto blob = StringVector::EmptyString(result, blob_size);
212668 auto writable_blob = blob.GetDataWriteable();
212669 Bignum::SetHeader(writable_blob, data_byte_size, false);
212670
212671 // Add data bytes to the blob, starting off after header bytes
212673 for (int i = static_cast<int>(upper_byte_size) - 1; i >= 0; --i) {
212674 writable_blob[wb_idx++] = static_cast<char>(int_value.upper >> i * 8 & 0xFF);
212675 }
212676 for (int i = static_cast<int>(data_byte_size - upper_byte_size) - 1; i >= 0; --i) {
212677 writable_blob[wb_idx++] = static_cast<char>(int_value.lower >> i * 8 & 0xFF);
212678 }
212679 blob.Finalize();
212680 bignum_t result_bignum(blob);
212681 return result_bignum;
212682}
static DUCKDB_API void SetHeader(char *blob, uint64_t number_of_bytes, bool is_negative)
Definition duckdb.cpp:112382
static DUCKDB_API constexpr uint8_t BIGNUM_HEADER_SIZE
Header size of a Bignum is always 3 bytes.
Definition duckdb.cpp:46515
__device__ __forceinline__ float1 log2(const uchar1 &a)
::uint32_t uint32_t
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static DUCKDB_API string_t EmptyString(Vector &vector, idx_t len)
Definition duckdb.cpp:137942

◆ Operation() [3/3]

template<>
bignum_t duckdb::HugeintCastToBignum::Operation ( hugeint_t int_value,
Vector & result )
212685 {
212686 // Determine if the number is negative
212687 bool is_negative = int_value.upper >> 63 & 1;
212688 if (is_negative) {
212689 // We must check if it's -170141183460469231731687303715884105728, since it's not possible to negate it
212690 // without overflowing
212691 if (int_value == NumericLimits<hugeint_t>::Minimum()) {
212692 uhugeint_t u_int_value {0x8000000000000000, 0};
212693 auto cast_value = Operation<uhugeint_t>(u_int_value, result);
212694 // We have to do all the bit flipping.
212695 auto writable_value_ptr = cast_value.data.GetDataWriteable();
212696 Bignum::SetHeader(writable_value_ptr, cast_value.data.GetSize() - Bignum::BIGNUM_HEADER_SIZE, is_negative);
212697 for (idx_t i = Bignum::BIGNUM_HEADER_SIZE; i < cast_value.data.GetSize(); i++) {
212698 writable_value_ptr[i] = static_cast<char>(~writable_value_ptr[i]);
212699 }
212700 cast_value.data.Finalize();
212701 return cast_value;
212702 }
212703 int_value = -int_value;
212704 }
212705 // Determine the number of data bytes
212706 uint64_t abs_value_upper = static_cast<uint64_t>(int_value.upper);
212707
212708 uint32_t data_byte_size;
212709 if (abs_value_upper != NumericLimits<uint64_t>::Maximum()) {
212710 data_byte_size =
212711 (abs_value_upper == 0) ? 0 : static_cast<uint32_t>(std::ceil(std::log2(abs_value_upper + 1) / 8.0));
212712 } else {
212713 data_byte_size = static_cast<uint32_t>(std::ceil(std::log2(abs_value_upper) / 8.0));
212714 }
212715
212716 uint32_t upper_byte_size = data_byte_size;
212717 if (data_byte_size > 0) {
212718 // If we have at least one byte on the upper side, the bottom side is complete
212719 data_byte_size += 8;
212720 } else {
212721 if (int_value.lower != NumericLimits<uint64_t>::Maximum()) {
212722 data_byte_size += static_cast<uint32_t>(std::ceil(std::log2(int_value.lower + 1) / 8.0));
212723 } else {
212724 data_byte_size += static_cast<uint32_t>(std::ceil(std::log2(int_value.lower) / 8.0));
212725 }
212726 }
212727
212728 if (data_byte_size == 0) {
212729 data_byte_size++;
212730 }
212731 uint32_t blob_size = data_byte_size + Bignum::BIGNUM_HEADER_SIZE;
212732 auto blob = StringVector::EmptyString(result, blob_size);
212733 auto writable_blob = blob.GetDataWriteable();
212734 Bignum::SetHeader(writable_blob, data_byte_size, is_negative);
212735
212736 // Add data bytes to the blob, starting off after header bytes
212738 for (int i = static_cast<int>(upper_byte_size) - 1; i >= 0; --i) {
212739 if (is_negative) {
212740 writable_blob[wb_idx++] = static_cast<char>(~(abs_value_upper >> i * 8 & 0xFF));
212741 } else {
212742 writable_blob[wb_idx++] = static_cast<char>(abs_value_upper >> i * 8 & 0xFF);
212743 }
212744 }
212745 for (int i = static_cast<int>(data_byte_size - upper_byte_size) - 1; i >= 0; --i) {
212746 if (is_negative) {
212747 writable_blob[wb_idx++] = static_cast<char>(~(int_value.lower >> i * 8 & 0xFF));
212748 } else {
212749 writable_blob[wb_idx++] = static_cast<char>(int_value.lower >> i * 8 & 0xFF);
212750 }
212751 }
212752 blob.Finalize();
212753 bignum_t result_bignum(blob);
212754 return result_bignum;
212755}
::uint64_t uint64_t

The documentation for this struct was generated from the following file: