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::HugeIntegerCastOperation Struct Reference

Static Public Member Functions

template<class T, bool NEGATIVE>
static bool HandleDigit (T &state, uint8_t digit)
template<class T, bool NEGATIVE>
static bool HandleHexDigit (T &state, uint8_t digit)
template<class T, bool NEGATIVE>
static bool HandleBinaryDigit (T &state, uint8_t digit)
template<class T, bool NEGATIVE>
static bool HandleExponent (T &state, int32_t exponent)
template<class T, bool NEGATIVE, bool ALLOW_EXPONENT>
static bool HandleDecimal (T &state, uint8_t digit)
template<class T, bool NEGATIVE>
static bool Finalize (T &state)

Member Function Documentation

◆ HandleDigit()

template<class T, bool NEGATIVE>
bool duckdb::HugeIntegerCastOperation::HandleDigit ( T & state,
uint8_t digit )
inlinestatic
90500 {
90501 if (NEGATIVE) {
90502 if (DUCKDB_UNLIKELY(state.intermediate <
90503 (NumericLimits<typename T::IntermediateType>::Minimum() + digit) / 10)) {
90504 // intermediate is full: need to flush it
90505 if (!state.Flush()) {
90506 return false;
90507 }
90508 }
90509 state.intermediate = state.intermediate * 10 - digit;
90510 } else {
90511 if (DUCKDB_UNLIKELY(state.intermediate >
90512 (NumericLimits<typename T::IntermediateType>::Maximum() - digit) / 10)) {
90513 if (!state.Flush()) {
90514 return false;
90515 }
90516 }
90517 state.intermediate = state.intermediate * 10 + digit;
90518 }
90519 state.digits++;
90520 return true;
90521 }

◆ HandleHexDigit()

template<class T, bool NEGATIVE>
bool duckdb::HugeIntegerCastOperation::HandleHexDigit ( T & state,
uint8_t digit )
inlinestatic
90524 {
90525 return false;
90526 }

◆ HandleBinaryDigit()

template<class T, bool NEGATIVE>
bool duckdb::HugeIntegerCastOperation::HandleBinaryDigit ( T & state,
uint8_t digit )
inlinestatic
90529 {
90530 return false;
90531 }

◆ HandleExponent()

template<class T, bool NEGATIVE>
bool duckdb::HugeIntegerCastOperation::HandleExponent ( T & state,
int32_t exponent )
inlinestatic
90534 {
90535 using result_t = typename T::ResultType;
90536 if (!state.Flush()) {
90537 return false;
90538 }
90539
90540 int32_t e = exponent;
90541 if (e < -38) {
90542 state.result = 0;
90543 return true;
90544 }
90545
90546 // Negative Exponent
90547 result_t remainder = 0;
90548 if (e < 0) {
90549 state.result = T::Operation::DivMod(state.result, T::Operation::POWERS_OF_TEN[-e], remainder);
90550 if (remainder < 0) {
90551 result_t negate_result;
90552 if (!T::Operation::TryNegate(remainder, negate_result)) {
90553 return false;
90554 }
90555 remainder = negate_result;
90556 }
90557 state.decimal = remainder;
90558 state.decimal_total_digits = static_cast<uint16_t>(-e);
90559 state.decimal_intermediate = 0;
90560 state.decimal_intermediate_digits = 0;
90561 return Finalize<T, NEGATIVE>(state);
90562 }
90563
90564 // Positive Exponent
90565 if (state.result != 0) {
90566 if (e > 38 || !TryMultiplyOperator::Operation(state.result, T::Operation::POWERS_OF_TEN[e], state.result)) {
90567 return false;
90568 }
90569 }
90570 if (!state.FlushDecimal()) {
90571 return false;
90572 }
90573 if (state.decimal == 0) {
90574 return Finalize<T, NEGATIVE>(state);
90575 }
90576
90577 e = exponent - state.decimal_total_digits;
90578 if (e < 0) {
90579 if (e < -38) {
90580 return false;
90581 }
90582 state.decimal = T::Operation::DivMod(state.decimal, T::Operation::POWERS_OF_TEN[-e], remainder);
90583 state.decimal_total_digits -= (exponent);
90584 } else {
90585 if (e > 38 ||
90586 !TryMultiplyOperator::Operation(state.decimal, T::Operation::POWERS_OF_TEN[e], state.decimal)) {
90587 return false;
90588 }
90589 }
90590
90591 if (NEGATIVE) {
90592 if (!TrySubtractOperator::Operation(state.result, state.decimal, state.result)) {
90593 return false;
90594 }
90595 } else if (!TryAddOperator::Operation(state.result, state.decimal, state.result)) {
90596 return false;
90597 }
90598 state.decimal = remainder;
90599 return Finalize<T, NEGATIVE>(state);
90600 }
::uint16_t uint16_t
::int32_t int32_t

◆ HandleDecimal()

template<class T, bool NEGATIVE, bool ALLOW_EXPONENT>
bool duckdb::HugeIntegerCastOperation::HandleDecimal ( T & state,
uint8_t digit )
inlinestatic
90603 {
90604 if (!state.Flush()) {
90605 return false;
90606 }
90607 if (DUCKDB_UNLIKELY(state.decimal_intermediate > (NumericLimits<int64_t>::Maximum() - digit) / 10)) {
90608 if (!state.FlushDecimal()) {
90609 return false;
90610 }
90611 }
90612 state.decimal_intermediate = state.decimal_intermediate * 10 + digit;
90613 state.decimal_intermediate_digits++;
90614 return true;
90615 }

◆ Finalize()

template<class T, bool NEGATIVE>
bool duckdb::HugeIntegerCastOperation::Finalize ( T & state)
inlinestatic
90618 {
90619 using result_t = typename T::ResultType;
90620 if (!state.Flush() || !state.FlushDecimal()) {
90621 return false;
90622 }
90623
90624 if (state.decimal == 0 || state.decimal_total_digits == 0) {
90625 return true;
90626 }
90627
90628 // Get the first (left-most) digit of the decimals
90629 constexpr auto MAX_DIGITS = T::Operation::CACHED_POWERS_OF_TEN - 1;
90630 while (state.decimal_total_digits > MAX_DIGITS) {
90631 state.decimal /= T::Operation::POWERS_OF_TEN[MAX_DIGITS];
90632 state.decimal_total_digits -= MAX_DIGITS;
90633 }
90634 D_ASSERT((state.decimal_total_digits - 1) >= 0 && (state.decimal_total_digits - 1) <= MAX_DIGITS);
90635 state.decimal /= T::Operation::POWERS_OF_TEN[state.decimal_total_digits - 1];
90636
90637 if (state.decimal >= 5) {
90638 if (NEGATIVE) {
90639 return TrySubtractOperator::Operation(state.result, result_t(1), state.result);
90640 } else {
90641 return TryAddOperator::Operation(state.result, result_t(1), state.result);
90642 }
90643 }
90644 return true;
90645 }

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