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::Bignum Class Reference

The Bignum class is a static class that holds helper functions for the Bignum type. More...

Static Public Member Functions

static DUCKDB_API void Verify (const bignum_t &input)
 
static DUCKDB_API void SetHeader (char *blob, uint64_t number_of_bytes, bool is_negative)
 
static DUCKDB_API bignum_t InitializeBignumZero (Vector &result)
 Initializes and returns a blob with value 0, allocated in Vector& result.
 
static DUCKDB_API string InitializeBignumZero ()
 
static DUCKDB_API BoundCastInfo NumericToBignumCastSwitch (const LogicalType &source)
 Switch Case of To Bignum Convertion.
 
static DUCKDB_API bool VarcharFormatting (const string_t &value, idx_t &start_pos, idx_t &end_pos, bool &is_negative, bool &is_zero)
 
static DUCKDB_API int CharToDigit (char c)
 Converts a char to a Digit.
 
static DUCKDB_API char DigitToChar (int digit)
 Converts a Digit to a char.
 
static DUCKDB_API void GetByteArray (vector< uint8_t > &byte_array, bool &is_negative, const string_t &blob)
 Function to convert a string_t into a vector of bytes.
 
static DUCKDB_API string FromByteArray (uint8_t *data, idx_t size, bool is_negative)
 Function to create a BIGNUM blob from a byte array containing the absolute value, plus an is_negative bool.
 
static DUCKDB_API string BignumToVarchar (const bignum_t &blob)
 Function to convert BIGNUM blob to a VARCHAR.
 
static DUCKDB_API string VarcharToBignum (const string_t &value)
 Function to convert Varchar to BIGNUM blob.
 
static DUCKDB_API bool BignumToDouble (const bignum_t &blob, double &result, bool &strict)
 --------------------------------— Double Cast --------------------------------— //
 
template<class T >
static bool BignumToInt (const bignum_t &blob, T &result, bool &strict)
 

Static Public Attributes

static DUCKDB_API constexpr uint32_t MAX_DATA_SIZE = 8388607
 
static DUCKDB_API constexpr uint8_t BIGNUM_HEADER_SIZE = 3
 Header size of a Bignum is always 3 bytes.
 
static DUCKDB_API constexpr uint8_t DECIMAL_SHIFT = 9
 Max(e such that 10**e fits in a digit_t)
 
static DUCKDB_API constexpr digit_t DECIMAL_BASE = 1000000000
 10 ** DECIMAL_SHIFT
 
static DUCKDB_API constexpr uint8_t DIGIT_BYTES = sizeof(digit_t)
 Bytes of a digit_t.
 
static DUCKDB_API constexpr uint8_t DIGIT_BITS = DIGIT_BYTES * 8
 Bits of a digit_t.
 

Detailed Description

The Bignum class is a static class that holds helper functions for the Bignum type.

Member Function Documentation

◆ Verify()

static DUCKDB_API void duckdb::Bignum::Verify ( const bignum_t input)
static

Verifies if a Bignum is valid. i.e., if it has 3 header bytes. The header correctly represents the number of data bytes, and the data bytes has no leading zero bytes.

◆ SetHeader()

static DUCKDB_API void duckdb::Bignum::SetHeader ( char blob,
uint64_t  number_of_bytes,
bool  is_negative 
)
static

Sets the header of a bignum (i.e., char* blob), depending on the number of bytes that bignum needs and if it's a negative number

Here is the caller graph for this function:

◆ VarcharFormatting()

static DUCKDB_API bool duckdb::Bignum::VarcharFormatting ( const string_t value,
idx_t start_pos,
idx_t end_pos,
bool &  is_negative,
bool &  is_zero 
)
static

--------------------------------— Varchar Cast --------------------------------— // Function to prepare a varchar for conversion. We trim zero's, check for negative values, and what-not Returns false if this is an invalid varchar

◆ BignumToInt()

template<class T >
static bool duckdb::Bignum::BignumToInt ( const bignum_t blob,
T &  result,
bool &  strict 
)
inlinestatic
46559 {
46560 auto data_byte_size = blob.data.GetSize() - BIGNUM_HEADER_SIZE;
46561 auto data = blob.data.GetData();
46562 bool is_negative = (data[0] & 0x80) == 0;
46563
46564 uhugeint_t abs_value = 0;
46565 for (idx_t i = 0; i < data_byte_size; ++i) {
46566 uint8_t byte = static_cast<uint8_t>(data[Bignum::BIGNUM_HEADER_SIZE + i]);
46567 if (is_negative) {
46568 byte = ~byte;
46569 }
46570 abs_value = (abs_value << 8) | byte;
46571 }
46572
46573 if (is_negative) {
46574 if (abs_value > static_cast<uhugeint_t>(std::numeric_limits<T>::max()) + 1) {
46575 throw OutOfRangeException("Negative bignum too small for type");
46576 }
46577 result = static_cast<T>(-static_cast<hugeint_t>(abs_value));
46578 } else {
46579 if (abs_value > static_cast<uhugeint_t>(std::numeric_limits<T>::max())) {
46580 throw OutOfRangeException("Positive bignum too large for type");
46581 }
46582 result = static_cast<T>(abs_value);
46583 }
46584 return true;
46585 }
static DUCKDB_API constexpr uint8_t BIGNUM_HEADER_SIZE
Header size of a Bignum is always 3 bytes.
Definition duckdb.cpp:46515
::uint8_t uint8_t

Member Data Documentation

◆ MAX_DATA_SIZE

DUCKDB_API constexpr uint32_t duckdb::Bignum::MAX_DATA_SIZE = 8388607
staticconstexpr

This is the maximum number of bytes a BIGNUM can have on it's data size i.e., 2^(8*3-1) - 1.


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