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

Public Member Functions

template<>
bool Operation (uint8_t left, uint8_t right, uint8_t &result)
template<>
bool Operation (uint16_t left, uint16_t right, uint16_t &result)
template<>
bool Operation (uint32_t left, uint32_t right, uint32_t &result)
template<>
bool Operation (uint64_t left, uint64_t right, uint64_t &result)
template<>
bool Operation (int8_t left, int8_t right, int8_t &result)
template<>
bool Operation (int16_t left, int16_t right, int16_t &result)
template<>
bool Operation (int32_t left, int32_t right, int32_t &result)
template<>
DUCKDB_API bool Operation (int64_t left, int64_t right, int64_t &result)
template<>
DUCKDB_API bool Operation (hugeint_t left, hugeint_t right, hugeint_t &result)
template<>
DUCKDB_API bool Operation (uhugeint_t left, uhugeint_t right, uhugeint_t &result)
template<>
bool Operation (interval_t left, double right, interval_t &result)
template<>
bool Operation (interval_t left, double right, interval_t &result)
template<>
bool Operation (uint8_t left, uint8_t right, uint8_t &result)
template<>
bool Operation (uint16_t left, uint16_t right, uint16_t &result)
template<>
bool Operation (uint32_t left, uint32_t right, uint32_t &result)
template<>
bool Operation (uint64_t left, uint64_t right, uint64_t &result)
template<>
bool Operation (int8_t left, int8_t right, int8_t &result)
template<>
bool Operation (int16_t left, int16_t right, int16_t &result)
template<>
bool Operation (int32_t left, int32_t right, int32_t &result)
template<>
bool Operation (int64_t left, int64_t right, int64_t &result)
template<>
bool Operation (hugeint_t left, hugeint_t right, hugeint_t &result)
template<>
bool Operation (uhugeint_t left, uhugeint_t right, uhugeint_t &result)

Static Public Member Functions

template<class TA, class TB, class TR>
static bool Operation (TA left, TB right, TR &result)

Member Function Documentation

◆ Operation() [1/12]

template<class TA, class TB, class TR>
bool duckdb::TryMultiplyOperator::Operation ( TA left,
TB right,
TR & result )
inlinestatic
53953 {
53954 throw InternalException("Unimplemented type for TryMultiplyOperator");
53955 }

◆ Operation() [2/12]

template<>
bool duckdb::TryMultiplyOperator::Operation ( interval_t left,
double right,
interval_t & result )
229452 {
229453 double d = left.months * right;
229454 if (std::isnan(d) || d < NumericLimits<int32_t>::Minimum() || d > NumericLimits<int32_t>::Maximum()) {
229455 return false;
229456 }
229457 result.months = LossyNumericCast<int32_t>(d);
229458
229459 d = left.days * right;
229460 if (std::isnan(d) || d < NumericLimits<int32_t>::Minimum() || d > NumericLimits<int32_t>::Maximum()) {
229461 return false;
229462 }
229463 result.days = LossyNumericCast<int32_t>(d);
229464
229465 /*
229466 * The above correctly handles the whole-number part of the month and day
229467 * products, but we have to do something with any fractional part
229468 * resulting when the factor is non-integral. We cascade the fractions
229469 * down to lower units using the conversion factors DAYS_PER_MONTH and
229470 * SECS_PER_DAY. Note we do NOT cascade up, since we are not forced to do
229471 * so by the representation. The user can choose to cascade up later,
229472 * using justify_hours and/or justify_days.
229473 */
229474
229475 /*
229476 * Fractional months full days into days.
229477 *
229478 * Floating point calculation are inherently imprecise, so these
229479 * calculations are crafted to produce the most reliable result possible.
229480 * TSROUND() is needed to more accurately produce whole numbers where
229481 * appropriate.
229482 */
229483 double month_remainder = (left.months * right - result.months) * Interval::DAYS_PER_MONTH;
229484 month_remainder = PGTimestampRound(month_remainder);
229485 auto day_remainder = LossyNumericCast<int32_t>(month_remainder);
229486
229487 double sec_remainder = (left.days * right - result.days + month_remainder - day_remainder) * Interval::SECS_PER_DAY;
229488 sec_remainder = PGTimestampRound(sec_remainder);
229489
229490 /*
229491 * Might have 24:00:00 hours due to rounding, or >24 hours because of time
229492 * cascade from months and days. It might still be >24 if the combination
229493 * of cascade and the seconds factor operation itself.
229494 */
229495 if (std::fabs(sec_remainder) >= Interval::SECS_PER_DAY) {
229496 result.days += LossyNumericCast<int32_t>(sec_remainder / Interval::SECS_PER_DAY);
229497 sec_remainder -= LossyNumericCast<int32_t>(sec_remainder / Interval::SECS_PER_DAY) * Interval::SECS_PER_DAY;
229498 }
229499
229500 /* cascade units down */
229501 result.days += day_remainder;
229502 if (!TryCast::Operation<int64_t, double>(left.micros, d)) {
229503 return false;
229504 }
229505 d = std::nearbyint(d * right + sec_remainder * Interval::MICROS_PER_SEC);
229506 if (std::isnan(d) || !TryCast::Operation<double, int64_t>(d, result.micros)) {
229507 return false;
229508 }
229509
229510 return true;
229511}
static constexpr const int64_t DAYS_PER_MONTH
only used for interval comparison/ordering purposes, in which case a month counts as 30 days
Definition duckdb.hpp:5258

◆ Operation() [3/12]

template<>
bool duckdb::TryMultiplyOperator::Operation ( uint8_t left,
uint8_t right,
uint8_t & result )
229545 {
229546 return OverflowCheckedMultiply::Operation<uint8_t, uint16_t>(left, right, result);
229547}

◆ Operation() [4/12]

template<>
bool duckdb::TryMultiplyOperator::Operation ( uint16_t left,
uint16_t right,
uint16_t & result )
229549 {
229550 return OverflowCheckedMultiply::Operation<uint16_t, uint32_t>(left, right, result);
229551}

◆ Operation() [5/12]

template<>
bool duckdb::TryMultiplyOperator::Operation ( uint32_t left,
uint32_t right,
uint32_t & result )
229553 {
229554 return OverflowCheckedMultiply::Operation<uint32_t, uint64_t>(left, right, result);
229555}

◆ Operation() [6/12]

template<>
bool duckdb::TryMultiplyOperator::Operation ( uint64_t left,
uint64_t right,
uint64_t & result )
229557 {
229558 if (left > right) {
229559 std::swap(left, right);
229560 }
229561 if (left > NumericLimits<uint32_t>::Maximum()) {
229562 return false;
229563 }
229564 uint32_t c = right >> 32;
229565 uint32_t d = NumericLimits<uint32_t>::Maximum() & right;
229566 uint64_t r = left * c;
229567 uint64_t s = left * d;
229568 if (r > NumericLimits<uint32_t>::Maximum()) {
229569 return false;
229570 }
229571 r <<= 32;
229572 if (NumericLimits<uint64_t>::Maximum() - s < r) {
229573 return false;
229574 }
229575 return OverflowCheckedMultiply::Operation<uint64_t, uint64_t>(left, right, result);
229576}
::uint32_t uint32_t
::uint64_t uint64_t

◆ Operation() [7/12]

template<>
bool duckdb::TryMultiplyOperator::Operation ( int8_t left,
int8_t right,
int8_t & result )
229579 {
229580 return OverflowCheckedMultiply::Operation<int8_t, int16_t>(left, right, result);
229581}

◆ Operation() [8/12]

template<>
bool duckdb::TryMultiplyOperator::Operation ( int16_t left,
int16_t right,
int16_t & result )
229584 {
229585 return OverflowCheckedMultiply::Operation<int16_t, int32_t>(left, right, result);
229586}

◆ Operation() [9/12]

template<>
bool duckdb::TryMultiplyOperator::Operation ( int32_t left,
int32_t right,
int32_t & result )
229589 {
229590 return OverflowCheckedMultiply::Operation<int32_t, int64_t>(left, right, result);
229591}

◆ Operation() [10/12]

template<>
bool duckdb::TryMultiplyOperator::Operation ( int64_t left,
int64_t right,
int64_t & result )
229594 {
229595#if (__GNUC__ >= 5) || defined(__clang__)
229596 if (__builtin_mul_overflow(left, right, &result)) {
229597 return false;
229598 }
229599#else
229600 if (left == std::numeric_limits<int64_t>::min()) {
229601 if (right == 0) {
229602 result = 0;
229603 return true;
229604 }
229605 if (right == 1) {
229606 result = left;
229607 return true;
229608 }
229609 return false;
229610 }
229611 if (right == std::numeric_limits<int64_t>::min()) {
229612 if (left == 0) {
229613 result = 0;
229614 return true;
229615 }
229616 if (left == 1) {
229617 result = right;
229618 return true;
229619 }
229620 return false;
229621 }
229622 uint64_t left_non_negative = uint64_t(std::abs(left));
229623 uint64_t right_non_negative = uint64_t(std::abs(right));
229624 // split values into 2 32-bit parts
229625 uint64_t left_high_bits = left_non_negative >> 32;
229626 uint64_t left_low_bits = left_non_negative & 0xffffffff;
229627 uint64_t right_high_bits = right_non_negative >> 32;
229628 uint64_t right_low_bits = right_non_negative & 0xffffffff;
229629
229630 // check the high bits of both
229631 // the high bits define the overflow
229632 if (left_high_bits == 0) {
229633 if (right_high_bits != 0) {
229634 // only the right has high bits set
229635 // multiply the high bits of right with the low bits of left
229636 // multiply the low bits, and carry any overflow to the high bits
229637 // then check for any overflow
229638 auto low_low = left_low_bits * right_low_bits;
229639 auto low_high = left_low_bits * right_high_bits;
229640 auto high_bits = low_high + (low_low >> 32);
229641 if (high_bits & 0xffffff80000000) {
229642 // there is! abort
229643 return false;
229644 }
229645 }
229646 } else if (right_high_bits == 0) {
229647 // only the left has high bits set
229648 // multiply the high bits of left with the low bits of right
229649 // multiply the low bits, and carry any overflow to the high bits
229650 // then check for any overflow
229651 auto low_low = left_low_bits * right_low_bits;
229652 auto high_low = left_high_bits * right_low_bits;
229653 auto high_bits = high_low + (low_low >> 32);
229654 if (high_bits & 0xffffff80000000) {
229655 // there is! abort
229656 return false;
229657 }
229658 } else {
229659 // both left and right have high bits set: guaranteed overflow
229660 // abort!
229661 return false;
229662 }
229663 // now we know that there is no overflow, we can just perform the multiplication
229664 result = left * right;
229665#endif
229666 return true;
229667}

◆ Operation() [11/12]

template<>
bool duckdb::TryMultiplyOperator::Operation ( hugeint_t left,
hugeint_t right,
hugeint_t & result )
229670 {
229671 return Hugeint::TryMultiply(left, right, result);
229672}

◆ Operation() [12/12]

template<>
bool duckdb::TryMultiplyOperator::Operation ( uhugeint_t left,
uhugeint_t right,
uhugeint_t & result )
229675 {
229676 return Uhugeint::TryMultiply(left, right, result);
229677}

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