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

The Hugeint class contains static operations for the INT128 type. More...

#include <duckdb.hpp>

Collaboration diagram for duckdb::Hugeint:

Public Member Functions

template<>
bool TryCast (hugeint_t input, int8_t &result)
template<>
bool TryCast (hugeint_t input, int16_t &result)
template<>
bool TryCast (hugeint_t input, int32_t &result)
template<>
bool TryCast (hugeint_t input, int64_t &result)
template<>
bool TryCast (hugeint_t input, uint8_t &result)
template<>
bool TryCast (hugeint_t input, uint16_t &result)
template<>
bool TryCast (hugeint_t input, uint32_t &result)
template<>
bool TryCast (hugeint_t input, uint64_t &result)
template<>
bool TryCast (hugeint_t input, hugeint_t &result)
template<>
bool TryCast (hugeint_t input, uhugeint_t &result)
template<>
bool TryCast (hugeint_t input, float &result)
template<>
bool TryCast (hugeint_t input, double &result)
template<>
bool TryCast (hugeint_t input, long double &result)
template<>
bool TryConvert (int8_t value, hugeint_t &result)
template<>
bool TryConvert (const char *value, hugeint_t &result)
template<>
bool TryConvert (int16_t value, hugeint_t &result)
template<>
bool TryConvert (int32_t value, hugeint_t &result)
template<>
bool TryConvert (int64_t value, hugeint_t &result)
template<>
bool TryConvert (uint8_t value, hugeint_t &result)
template<>
bool TryConvert (uint16_t value, hugeint_t &result)
template<>
bool TryConvert (uint32_t value, hugeint_t &result)
template<>
bool TryConvert (uint64_t value, hugeint_t &result)
template<>
bool TryConvert (hugeint_t value, hugeint_t &result)
template<>
bool TryConvert (float value, hugeint_t &result)
template<>
bool TryConvert (double value, hugeint_t &result)
template<>
bool TryConvert (long double value, hugeint_t &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, int8_t &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, int16_t &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, int32_t &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, int64_t &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, uint8_t &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, uint16_t &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, uint32_t &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, uint64_t &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, hugeint_t &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, uhugeint_t &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, float &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, double &result)
template<>
DUCKDB_API bool TryCast (hugeint_t input, long double &result)
template<>
bool TryConvert (int8_t value, hugeint_t &result)
template<>
bool TryConvert (int16_t value, hugeint_t &result)
template<>
bool TryConvert (int32_t value, hugeint_t &result)
template<>
bool TryConvert (int64_t value, hugeint_t &result)
template<>
bool TryConvert (uint8_t value, hugeint_t &result)
template<>
bool TryConvert (uint16_t value, hugeint_t &result)
template<>
bool TryConvert (uint32_t value, hugeint_t &result)
template<>
bool TryConvert (uint64_t value, hugeint_t &result)
template<>
bool TryConvert (float value, hugeint_t &result)
template<>
bool TryConvert (double value, hugeint_t &result)
template<>
bool TryConvert (long double value, hugeint_t &result)
template<>
bool TryConvert (const char *value, hugeint_t &result)

Static Public Member Functions

static string ToString (hugeint_t input)
 Convert a hugeint object to a string.
template<class T>
static DUCKDB_API bool TryCast (hugeint_t input, T &result)
template<class T>
static T Cast (hugeint_t input)
template<class T>
static bool TryConvert (T value, hugeint_t &result)
template<class T>
static hugeint_t Convert (T value)
static bool TryNegate (hugeint_t input, hugeint_t &result)
template<bool CHECK_OVERFLOW = true>
static void NegateInPlace (hugeint_t &input)
template<bool CHECK_OVERFLOW = true>
static hugeint_t Negate (hugeint_t input)
static bool TryMultiply (hugeint_t lhs, hugeint_t rhs, hugeint_t &result)
template<bool CHECK_OVERFLOW = true>
static hugeint_t Multiply (hugeint_t lhs, hugeint_t rhs)
static bool TryDivMod (hugeint_t lhs, hugeint_t rhs, hugeint_t &result, hugeint_t &remainder)
template<bool CHECK_OVERFLOW = true>
static hugeint_t Divide (hugeint_t lhs, hugeint_t rhs)
template<bool CHECK_OVERFLOW = true>
static hugeint_t Modulo (hugeint_t lhs, hugeint_t rhs)
static bool TryAddInPlace (hugeint_t &lhs, hugeint_t rhs)
template<bool CHECK_OVERFLOW = true>
static hugeint_t Add (hugeint_t lhs, hugeint_t rhs)
static bool TrySubtractInPlace (hugeint_t &lhs, hugeint_t rhs)
template<bool CHECK_OVERFLOW = true>
static hugeint_t Subtract (hugeint_t lhs, hugeint_t rhs)
static hugeint_t DivMod (hugeint_t lhs, hugeint_t rhs, hugeint_t &remainder)
static hugeint_t DivModPositive (hugeint_t lhs, uint64_t rhs, uint64_t &remainder)
static int Sign (hugeint_t n)
static hugeint_t Abs (hugeint_t n)
static bool Equals (const hugeint_t &lhs, const hugeint_t &rhs)
static bool NotEquals (const hugeint_t &lhs, const hugeint_t &rhs)
static bool GreaterThan (const hugeint_t &lhs, const hugeint_t &rhs)
static bool GreaterThanEquals (const hugeint_t &lhs, const hugeint_t &rhs)
static bool LessThan (const hugeint_t &lhs, const hugeint_t &rhs)
static bool LessThanEquals (const hugeint_t &lhs, const hugeint_t &rhs)
template<>
void NegateInPlace (hugeint_t &input)
template<>
hugeint_t Multiply (hugeint_t lhs, hugeint_t rhs)
template<>
hugeint_t Divide (hugeint_t lhs, hugeint_t rhs)
template<>
hugeint_t Modulo (hugeint_t lhs, hugeint_t rhs)
template<>
hugeint_t Add (hugeint_t lhs, hugeint_t rhs)
template<>
hugeint_t Subtract (hugeint_t lhs, hugeint_t rhs)

Static Public Attributes

static constexpr const char * HUGEINT_MINIMUM_STRING = "-170141183460469231731687303715884105728"
static constexpr uint8_t CACHED_POWERS_OF_TEN = 39
static const hugeint_t POWERS_OF_TEN [CACHED_POWERS_OF_TEN]

Detailed Description

The Hugeint class contains static operations for the INT128 type.

Member Function Documentation

◆ ToString()

string duckdb::Hugeint::ToString ( hugeint_t input)
static

Convert a hugeint object to a string.

121920 {
121921 uint64_t remainder;
121922 string result;
121923 if (input == NumericLimits<hugeint_t>::Minimum()) {
121924 return string(Hugeint::HUGEINT_MINIMUM_STRING);
121925 }
121926 bool negative = input.upper < 0;
121927 if (negative) {
121928 NegateInPlace(input);
121929 }
121930 while (true) {
121931 if (!input.lower && !input.upper) {
121932 break;
121933 }
121934 input = Hugeint::DivModPositive(input, 10, remainder);
121935 result = string(1, UnsafeNumericCast<char>('0' + remainder)) + result; // NOLINT
121936 }
121937 if (result.empty()) {
121938 // value is zero
121939 return "0";
121940 }
121941 return negative ? "-" + result : result;
121942}
::uint64_t uint64_t

◆ Cast()

template<class T>
T duckdb::Hugeint::Cast ( hugeint_t input)
inlinestatic
14166 {
14167 T result = 0;
14168 TryCast(input, result);
14169 return result;
14170 }

◆ Convert()

template<class T>
hugeint_t duckdb::Hugeint::Convert ( T value)
inlinestatic
14176 {
14177 hugeint_t result;
14178 if (!TryConvert(value, result)) { // LCOV_EXCL_START
14179 throw OutOfRangeException(double(value), GetTypeId<T>(), GetTypeId<hugeint_t>());
14180 } // LCOV_EXCL_STOP
14181 return result;
14182 }
PhysicalType GetTypeId()
Returns the PhysicalType for the given type.
Definition duckdb.hpp:10381

◆ TryNegate()

bool duckdb::Hugeint::TryNegate ( hugeint_t input,
hugeint_t & result )
static
121828 {
121829 if (input.upper == NumericLimits<int64_t>::Minimum() && input.lower == 0) {
121830 return false;
121831 }
121832 NegateInPlace<false>(input);
121833 result = input;
121834 return true;
121835}

◆ NegateInPlace() [1/2]

template<bool CHECK_OVERFLOW = true>
void duckdb::Hugeint::NegateInPlace ( hugeint_t & input)
inlinestatic
14187 {
14188 if (!TryNegate(input, input)) {
14189 throw OutOfRangeException("Negation of HUGEINT is out of range!");
14190 }
14191 }

◆ Negate()

template<bool CHECK_OVERFLOW = true>
hugeint_t duckdb::Hugeint::Negate ( hugeint_t input)
inlinestatic
14194 {
14195 NegateInPlace<CHECK_OVERFLOW>(input);
14196 return input;
14197 }

◆ TryMultiply()

bool duckdb::Hugeint::TryMultiply ( hugeint_t lhs,
hugeint_t rhs,
hugeint_t & result )
static
121949 {
121950 // Check if one of the sides is hugeint_t minimum, as that can't be negated.
121951 // You can only multiply the minimum by 0 or 1, any other value will result in overflow
121952 if (lhs == NumericLimits<hugeint_t>::Minimum() || rhs == NumericLimits<hugeint_t>::Minimum()) {
121953 if (lhs == 0 || rhs == 0) {
121954 result = 0;
121955 return true;
121956 }
121957 if (lhs == 1 || rhs == 1) {
121958 result = NumericLimits<hugeint_t>::Minimum();
121959 return true;
121960 }
121961 return false;
121962 }
121963
121964 bool lhs_negative = lhs.upper < 0;
121965 bool rhs_negative = rhs.upper < 0;
121966 if (lhs_negative && !TryNegate(lhs, lhs)) {
121967 return false;
121968 }
121969 if (rhs_negative && !TryNegate(rhs, rhs)) {
121970 return false;
121971 }
121972
121973#if ((__GNUC__ >= 5) || defined(__clang__)) && defined(__SIZEOF_INT128__)
121974 __uint128_t left = __uint128_t(lhs.lower) + (__uint128_t(lhs.upper) << 64);
121975 __uint128_t right = __uint128_t(rhs.lower) + (__uint128_t(rhs.upper) << 64);
121976 __uint128_t result_i128;
121977 if (__builtin_mul_overflow(left, right, &result_i128)) {
121978 return false;
121979 }
121980 uint64_t upper = uint64_t(result_i128 >> 64);
121981 if (upper & 0x8000000000000000) {
121982 return false;
121983 }
121984 result.upper = int64_t(upper);
121985 result.lower = uint64_t(result_i128 & 0xffffffffffffffff);
121986#else
121987 // Multiply code adapted from:
121988 // https://github.com/calccrypto/uint128_t/blob/master/uint128_t.cpp
121989
121990 // split values into 4 32-bit parts
121991 uint64_t top[4] = {uint64_t(lhs.upper) >> 32, uint64_t(lhs.upper) & 0xffffffff, lhs.lower >> 32,
121992 lhs.lower & 0xffffffff};
121993 uint64_t bottom[4] = {uint64_t(rhs.upper) >> 32, uint64_t(rhs.upper) & 0xffffffff, rhs.lower >> 32,
121994 rhs.lower & 0xffffffff};
121995 uint64_t products[4][4];
121996
121997 // multiply each component of the values
121998 for (auto x = 0; x < 4; x++) {
121999 for (auto y = 0; y < 4; y++) {
122000 products[x][y] = top[x] * bottom[y];
122001 }
122002 }
122003
122004 // if any of these products are set to a non-zero value, there is always an overflow
122005 if (products[0][0] || products[0][1] || products[0][2] || products[1][0] || products[2][0] || products[1][1]) {
122006 return false;
122007 }
122008 // if the high bits of any of these are set, there is always an overflow
122009 if ((products[0][3] & 0xffffffff80000000) || (products[1][2] & 0xffffffff80000000) ||
122010 (products[2][1] & 0xffffffff80000000) || (products[3][0] & 0xffffffff80000000)) {
122011 return false;
122012 }
122013
122014 // otherwise we merge the result of the different products together in-order
122015
122016 // first row
122017 uint64_t fourth32 = (products[3][3] & 0xffffffff);
122018 uint64_t third32 = (products[3][2] & 0xffffffff) + (products[3][3] >> 32);
122019 uint64_t second32 = (products[3][1] & 0xffffffff) + (products[3][2] >> 32);
122020 uint64_t first32 = (products[3][0] & 0xffffffff) + (products[3][1] >> 32);
122021
122022 // second row
122023 third32 += (products[2][3] & 0xffffffff);
122024 second32 += (products[2][2] & 0xffffffff) + (products[2][3] >> 32);
122025 first32 += (products[2][1] & 0xffffffff) + (products[2][2] >> 32);
122026
122027 // third row
122028 second32 += (products[1][3] & 0xffffffff);
122029 first32 += (products[1][2] & 0xffffffff) + (products[1][3] >> 32);
122030
122031 // fourth row
122032 first32 += (products[0][3] & 0xffffffff);
122033
122034 // move carry to next digit
122035 third32 += fourth32 >> 32;
122036 second32 += third32 >> 32;
122037 first32 += second32 >> 32;
122038
122039 // check if the combination of the different products resulted in an overflow
122040 if (first32 & 0xffffff80000000) {
122041 return false;
122042 }
122043
122044 // remove carry from current digit
122045 fourth32 &= 0xffffffff;
122046 third32 &= 0xffffffff;
122047 second32 &= 0xffffffff;
122048 first32 &= 0xffffffff;
122049
122050 // combine components
122051 result.lower = (third32 << 32) | fourth32;
122052 result.upper = (first32 << 32) | second32;
122053#endif
122054 if (lhs_negative ^ rhs_negative) {
122055 NegateInPlace<false>(result);
122056 }
122057 return true;
122058}
::int64_t int64_t

◆ Multiply() [1/2]

template<bool CHECK_OVERFLOW = true>
hugeint_t duckdb::Hugeint::Multiply ( hugeint_t lhs,
hugeint_t rhs )
inlinestatic
14202 {
14203 hugeint_t result;
14204 if (!TryMultiply(lhs, rhs, result)) {
14205 throw OutOfRangeException("Overflow in HUGEINT multiplication: %s * %s", lhs.ToString(), rhs.ToString());
14206 }
14207 return result;
14208 }

◆ TryDivMod()

bool duckdb::Hugeint::TryDivMod ( hugeint_t lhs,
hugeint_t rhs,
hugeint_t & result,
hugeint_t & remainder )
static
122231 {
122232 // No division by zero
122233 if (rhs == 0) {
122234 return false;
122235 }
122236
122237 // division only has one reason to overflow: MINIMUM / -1
122238 if (lhs == NumericLimits<hugeint_t>::Minimum() && rhs == -1) {
122239 return false;
122240 }
122241
122242 result = Hugeint::DivMod(lhs, rhs, remainder);
122243 return true;
122244}

◆ Divide() [1/2]

template<bool CHECK_OVERFLOW = true>
hugeint_t duckdb::Hugeint::Divide ( hugeint_t lhs,
hugeint_t rhs )
inlinestatic
14213 {
14214 // No division by zero
14215 if (rhs == 0) {
14216 throw OutOfRangeException("Division of HUGEINT by zero: %s / %s", lhs.ToString(), rhs.ToString());
14217 }
14218
14219 // division only has one reason to overflow: MINIMUM / -1
14220 if (lhs == NumericLimits<hugeint_t>::Minimum() && rhs == -1) {
14221 throw OutOfRangeException("Overflow in HUGEINT division: %s / %s", lhs.ToString(), rhs.ToString());
14222 }
14223 return Divide<false>(lhs, rhs);
14224 }

◆ Modulo() [1/2]

template<bool CHECK_OVERFLOW = true>
hugeint_t duckdb::Hugeint::Modulo ( hugeint_t lhs,
hugeint_t rhs )
inlinestatic
14227 {
14228 // No division by zero
14229 if (rhs == 0) {
14230 throw OutOfRangeException("Modulo of HUGEINT by zero: %s %% %s", lhs.ToString(), rhs.ToString());
14231 }
14232
14233 // division only has one reason to overflow: MINIMUM / -1
14234 if (lhs == NumericLimits<hugeint_t>::Minimum() && rhs == -1) {
14235 throw OutOfRangeException("Overflow in HUGEINT modulo: %s %% %s", lhs.ToString(), rhs.ToString());
14236 }
14237 return Modulo<false>(lhs, rhs);
14238 }

◆ TryAddInPlace()

bool duckdb::Hugeint::TryAddInPlace ( hugeint_t & lhs,
hugeint_t rhs )
static
122262 {
122263 int overflow = lhs.lower + rhs.lower < lhs.lower;
122264 if (rhs.upper >= 0) {
122265 // RHS is positive: check for overflow
122266 if (lhs.upper > (std::numeric_limits<int64_t>::max() - rhs.upper - overflow)) {
122267 return false;
122268 }
122269 lhs.upper = lhs.upper + overflow + rhs.upper;
122270 } else {
122271 // RHS is negative: check for underflow
122272 if (lhs.upper < std::numeric_limits<int64_t>::min() - rhs.upper - overflow) {
122273 return false;
122274 }
122275 lhs.upper = lhs.upper + (overflow + rhs.upper);
122276 }
122277 lhs.lower += rhs.lower;
122278 return true;
122279}

◆ Add() [1/2]

template<bool CHECK_OVERFLOW = true>
hugeint_t duckdb::Hugeint::Add ( hugeint_t lhs,
hugeint_t rhs )
inlinestatic
14243 {
14244 if (!TryAddInPlace(lhs, rhs)) {
14245 throw OutOfRangeException("Overflow in HUGEINT addition: %s + %s", lhs.ToString(), rhs.ToString());
14246 }
14247 return lhs;
14248 }

◆ TrySubtractInPlace()

bool duckdb::Hugeint::TrySubtractInPlace ( hugeint_t & lhs,
hugeint_t rhs )
static
122281 {
122282 // underflow
122283 int underflow = lhs.lower - rhs.lower > lhs.lower;
122284 if (rhs.upper >= 0) {
122285 // RHS is positive: check for underflow
122286 if (lhs.upper < (std::numeric_limits<int64_t>::min() + rhs.upper + underflow)) {
122287 return false;
122288 }
122289 lhs.upper = (lhs.upper - rhs.upper) - underflow;
122290 } else {
122291 // RHS is negative: check for overflow
122292 if (lhs.upper > std::numeric_limits<int64_t>::min() &&
122293 lhs.upper - 1 >= (std::numeric_limits<int64_t>::max() + rhs.upper + underflow)) {
122294 return false;
122295 }
122296 lhs.upper = lhs.upper - (rhs.upper + underflow);
122297 }
122298 lhs.lower -= rhs.lower;
122299 return true;
122300}

◆ Subtract() [1/2]

template<bool CHECK_OVERFLOW = true>
hugeint_t duckdb::Hugeint::Subtract ( hugeint_t lhs,
hugeint_t rhs )
inlinestatic
14253 {
14254 if (!TrySubtractInPlace(lhs, rhs)) {
14255 throw OutOfRangeException("Underflow in HUGEINT subtraction: %s - %s", lhs.ToString(), rhs.ToString());
14256 }
14257 return lhs;
14258 }

◆ DivMod()

hugeint_t duckdb::Hugeint::DivMod ( hugeint_t lhs,
hugeint_t rhs,
hugeint_t & remainder )
static
122176 {
122177 if (rhs == 0) {
122178 remainder = lhs;
122179 return hugeint_t(0);
122180 }
122181
122182 // Check if one of the sides is hugeint_t minimum, as that can't be negated.
122183 if (lhs == NumericLimits<hugeint_t>::Minimum() || rhs == NumericLimits<hugeint_t>::Minimum()) {
122184 return DivModMinimum(lhs, rhs, remainder);
122185 }
122186
122187 bool lhs_negative = lhs.upper < 0;
122188 bool rhs_negative = rhs.upper < 0;
122189 if (lhs_negative) {
122190 Hugeint::NegateInPlace<false>(lhs);
122191 }
122192 if (rhs_negative) {
122193 Hugeint::NegateInPlace<false>(rhs);
122194 }
122195 // DivMod code adapted from:
122196 // https://github.com/calccrypto/uint128_t/blob/master/uint128_t.cpp
122197
122198 // initialize the result and remainder to 0
122199 hugeint_t div_result;
122200 div_result.lower = 0;
122201 div_result.upper = 0;
122202 remainder.lower = 0;
122203 remainder.upper = 0;
122204
122205 uint8_t highest_bit_set = PositiveHugeintHighestBit(lhs);
122206 // now iterate over the amount of bits that are set in the LHS
122207 for (uint8_t x = highest_bit_set; x > 0; x--) {
122208 // left-shift the current result and remainder by 1
122209 div_result = PositiveHugeintLeftShift(div_result, 1);
122210 remainder = PositiveHugeintLeftShift(remainder, 1);
122211
122212 // we get the value of the bit at position X, where position 0 is the least-significant bit
122213 if (PositiveHugeintIsBitSet(lhs, x - 1)) {
122214 remainder += 1;
122215 }
122216 if (Hugeint::GreaterThanEquals(remainder, rhs)) {
122217 // the remainder has passed the division multiplier: add one to the divide result
122218 remainder -= rhs;
122219 div_result += 1;
122220 }
122221 }
122222 if (lhs_negative ^ rhs_negative) {
122223 Hugeint::NegateInPlace<false>(div_result);
122224 }
122225 if (lhs_negative) {
122226 Hugeint::NegateInPlace<false>(remainder);
122227 }
122228 return div_result;
122229}
::uint8_t uint8_t

◆ DivModPositive()

hugeint_t duckdb::Hugeint::DivModPositive ( hugeint_t lhs,
uint64_t rhs,
uint64_t & remainder )
static
121885 {
121886 D_ASSERT(lhs.upper >= 0);
121887 // DivMod code adapted from:
121888 // https://github.com/calccrypto/uint128_t/blob/master/uint128_t.cpp
121889
121890 // initialize the result and remainder to 0
121891 hugeint_t div_result;
121892 div_result.lower = 0;
121893 div_result.upper = 0;
121894 remainder = 0;
121895
121896 uint8_t highest_bit_set = PositiveHugeintHighestBit(lhs);
121897 // now iterate over the amount of bits that are set in the LHS
121898 for (uint8_t x = highest_bit_set; x > 0; x--) {
121899 // left-shift the current result and remainder by 1
121900 div_result = PositiveHugeintLeftShift(div_result, 1);
121901 remainder <<= 1;
121902 // we get the value of the bit at position X, where position 0 is the least-significant bit
121903 if (PositiveHugeintIsBitSet(lhs, x - 1)) {
121904 // increment the remainder
121905 remainder++;
121906 }
121907 if (remainder >= rhs) {
121908 // the remainder has passed the division multiplier: add one to the divide result
121909 remainder -= rhs;
121910 div_result.lower++;
121911 if (div_result.lower == 0) {
121912 // overflow
121913 div_result.upper++;
121914 }
121915 }
121916 }
121917 return div_result;
121918}

◆ Abs()

hugeint_t duckdb::Hugeint::Abs ( hugeint_t n)
static
121837 {
121838 if (n < 0) {
121839 return Hugeint::Negate(n);
121840 } else {
121841 return n;
121842 }
121843}

◆ Equals()

bool duckdb::Hugeint::Equals ( const hugeint_t & lhs,
const hugeint_t & rhs )
inlinestatic
14268 {
14269 bool lower_equals = lhs.lower == rhs.lower;
14270 bool upper_equals = lhs.upper == rhs.upper;
14271 return lower_equals && upper_equals;
14272 }

◆ NotEquals()

bool duckdb::Hugeint::NotEquals ( const hugeint_t & lhs,
const hugeint_t & rhs )
inlinestatic
14274 {
14275 return !Equals(lhs, rhs);
14276 }

◆ GreaterThan()

bool duckdb::Hugeint::GreaterThan ( const hugeint_t & lhs,
const hugeint_t & rhs )
inlinestatic
14278 {
14279 bool upper_bigger = lhs.upper > rhs.upper;
14280 bool upper_equal = lhs.upper == rhs.upper;
14281 bool lower_bigger = lhs.lower > rhs.lower;
14282 return upper_bigger || (upper_equal && lower_bigger);
14283 }

◆ GreaterThanEquals()

bool duckdb::Hugeint::GreaterThanEquals ( const hugeint_t & lhs,
const hugeint_t & rhs )
inlinestatic
14285 {
14286 bool upper_bigger = lhs.upper > rhs.upper;
14287 bool upper_equal = lhs.upper == rhs.upper;
14288 bool lower_bigger_equals = lhs.lower >= rhs.lower;
14289 return upper_bigger || (upper_equal && lower_bigger_equals);
14290 }

◆ LessThan()

bool duckdb::Hugeint::LessThan ( const hugeint_t & lhs,
const hugeint_t & rhs )
inlinestatic
14292 {
14293 bool upper_smaller = lhs.upper < rhs.upper;
14294 bool upper_equal = lhs.upper == rhs.upper;
14295 bool lower_smaller = lhs.lower < rhs.lower;
14296 return upper_smaller || (upper_equal && lower_smaller);
14297 }

◆ LessThanEquals()

bool duckdb::Hugeint::LessThanEquals ( const hugeint_t & lhs,
const hugeint_t & rhs )
inlinestatic
14299 {
14300 bool upper_smaller = lhs.upper < rhs.upper;
14301 bool upper_equal = lhs.upper == rhs.upper;
14302 bool lower_smaller_equals = lhs.lower <= rhs.lower;
14303 return upper_smaller || (upper_equal && lower_smaller_equals);
14304 }

◆ NegateInPlace() [2/2]

template<>
void duckdb::Hugeint::NegateInPlace ( hugeint_t & input)
static
121823 {
121824 input.lower = NumericLimits<uint64_t>::Maximum() - input.lower + 1ull;
121825 input.upper = -1 - input.upper + (input.lower == 0);
121826}

◆ Multiply() [2/2]

template<>
hugeint_t duckdb::Hugeint::Multiply ( hugeint_t lhs,
hugeint_t rhs )
static
122062 {
122063 hugeint_t result;
122064 bool lhs_negative = lhs.upper < 0;
122065 bool rhs_negative = rhs.upper < 0;
122066 if (lhs_negative) {
122067 NegateInPlace<false>(lhs);
122068 }
122069 if (rhs_negative) {
122070 NegateInPlace<false>(rhs);
122071 }
122072
122073#if ((__GNUC__ >= 5) || defined(__clang__)) && defined(__SIZEOF_INT128__)
122074 __uint128_t left = __uint128_t(lhs.lower) + (__uint128_t(lhs.upper) << 64);
122075 __uint128_t right = __uint128_t(rhs.lower) + (__uint128_t(rhs.upper) << 64);
122076 __uint128_t result_i128;
122077 result_i128 = left * right;
122078 uint64_t upper = uint64_t(result_i128 >> 64);
122079 result.upper = int64_t(upper);
122080 result.lower = uint64_t(result_i128 & 0xffffffffffffffff);
122081#else
122082 // Multiply code adapted from:
122083 // https://github.com/calccrypto/uint128_t/blob/master/uint128_t.cpp
122084
122085 // split values into 4 32-bit parts
122086 uint64_t top[4] = {uint64_t(lhs.upper) >> 32, uint64_t(lhs.upper) & 0xffffffff, lhs.lower >> 32,
122087 lhs.lower & 0xffffffff};
122088 uint64_t bottom[4] = {uint64_t(rhs.upper) >> 32, uint64_t(rhs.upper) & 0xffffffff, rhs.lower >> 32,
122089 rhs.lower & 0xffffffff};
122090 uint64_t products[4][4];
122091
122092 // multiply each component of the values
122093 for (auto x = 0; x < 4; x++) {
122094 for (auto y = 0; y < 4; y++) {
122095 products[x][y] = top[x] * bottom[y];
122096 }
122097 }
122098
122099 // first row
122100 uint64_t fourth32 = (products[3][3] & 0xffffffff);
122101 uint64_t third32 = (products[3][2] & 0xffffffff) + (products[3][3] >> 32);
122102 uint64_t second32 = (products[3][1] & 0xffffffff) + (products[3][2] >> 32);
122103 uint64_t first32 = (products[3][0] & 0xffffffff) + (products[3][1] >> 32);
122104
122105 // second row
122106 third32 += (products[2][3] & 0xffffffff);
122107 second32 += (products[2][2] & 0xffffffff) + (products[2][3] >> 32);
122108 first32 += (products[2][1] & 0xffffffff) + (products[2][2] >> 32);
122109
122110 // third row
122111 second32 += (products[1][3] & 0xffffffff);
122112 first32 += (products[1][2] & 0xffffffff) + (products[1][3] >> 32);
122113
122114 // fourth row
122115 first32 += (products[0][3] & 0xffffffff);
122116
122117 // move carry to next digit
122118 third32 += fourth32 >> 32;
122119 second32 += third32 >> 32;
122120 first32 += second32 >> 32;
122121
122122 // remove carry from current digit
122123 fourth32 &= 0xffffffff;
122124 third32 &= 0xffffffff;
122125 second32 &= 0xffffffff;
122126 first32 &= 0xffffffff;
122127
122128 // combine components
122129 result.lower = (third32 << 32) | fourth32;
122130 result.upper = (first32 << 32) | second32;
122131#endif
122132 if (lhs_negative ^ rhs_negative) {
122133 NegateInPlace<false>(result);
122134 }
122135 return result;
122136}

◆ Divide() [2/2]

template<>
hugeint_t duckdb::Hugeint::Divide ( hugeint_t lhs,
hugeint_t rhs )
static
122247 {
122248 hugeint_t remainder;
122249 return Hugeint::DivMod(lhs, rhs, remainder);
122250}

◆ Modulo() [2/2]

template<>
hugeint_t duckdb::Hugeint::Modulo ( hugeint_t lhs,
hugeint_t rhs )
static
122253 {
122254 hugeint_t remainder;
122255 (void)Hugeint::DivMod(lhs, rhs, remainder);
122256 return remainder;
122257}

◆ Add() [2/2]

template<>
hugeint_t duckdb::Hugeint::Add ( hugeint_t lhs,
hugeint_t rhs )
static
122303 {
122304 return lhs + rhs;
122305}

◆ Subtract() [2/2]

template<>
hugeint_t duckdb::Hugeint::Subtract ( hugeint_t lhs,
hugeint_t rhs )
static
122308 {
122309 return lhs - rhs;
122310}

◆ TryCast() [1/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
int8_t & result )
122342 {
122343 return HugeintTryCastInteger<int8_t>(input, result);
122344}

◆ TryCast() [2/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
int16_t & result )
122347 {
122348 return HugeintTryCastInteger<int16_t>(input, result);
122349}

◆ TryCast() [3/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
int32_t & result )
122352 {
122353 return HugeintTryCastInteger<int32_t>(input, result);
122354}

◆ TryCast() [4/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
int64_t & result )
122357 {
122358 return HugeintTryCastInteger<int64_t>(input, result);
122359}

◆ TryCast() [5/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
uint8_t & result )
122362 {
122363 return HugeintTryCastInteger<uint8_t, false>(input, result);
122364}

◆ TryCast() [6/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
uint16_t & result )
122367 {
122368 return HugeintTryCastInteger<uint16_t, false>(input, result);
122369}

◆ TryCast() [7/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
uint32_t & result )
122372 {
122373 return HugeintTryCastInteger<uint32_t, false>(input, result);
122374}

◆ TryCast() [8/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
uint64_t & result )
122377 {
122378 return HugeintTryCastInteger<uint64_t, false>(input, result);
122379}

◆ TryCast() [9/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
hugeint_t & result )
122382 {
122383 result = input;
122384 return true;
122385}

◆ TryCast() [10/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
uhugeint_t & result )
122388 {
122389 if (input < 0) {
122390 return false;
122391 }
122392
122393 result.lower = input.lower;
122394 result.upper = UnsafeNumericCast<uint64_t>(input.upper);
122395 return true;
122396}

◆ TryCast() [11/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
float & result )
122399 {
122400 double dbl_result;
122401 Hugeint::TryCast(input, dbl_result);
122402 result = (float)dbl_result;
122403 return true;
122404}

◆ TryCast() [12/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
double & result )
122421 {
122422 return CastBigintToFloating<double>(input, result);
122423}

◆ TryCast() [13/13]

template<>
bool duckdb::Hugeint::TryCast ( hugeint_t input,
long double & result )
122426 {
122427 return CastBigintToFloating<long double>(input, result);
122428}

◆ TryConvert() [1/13]

template<>
bool duckdb::Hugeint::TryConvert ( int8_t value,
hugeint_t & result )
122439 {
122440 result = HugeintConvertInteger<int8_t>(value);
122441 return true;
122442}

◆ TryConvert() [2/13]

template<>
bool duckdb::Hugeint::TryConvert ( const char * value,
hugeint_t & result )
122445 {
122446 auto len = strlen(value);
122447 string_t string_val(value, UnsafeNumericCast<uint32_t>(len));
122448 return TryCast::Operation<string_t, hugeint_t>(string_val, result, true);
122449}

◆ TryConvert() [3/13]

template<>
bool duckdb::Hugeint::TryConvert ( int16_t value,
hugeint_t & result )
122452 {
122453 result = HugeintConvertInteger<int16_t>(value);
122454 return true;
122455}

◆ TryConvert() [4/13]

template<>
bool duckdb::Hugeint::TryConvert ( int32_t value,
hugeint_t & result )
122458 {
122459 result = HugeintConvertInteger<int32_t>(value);
122460 return true;
122461}

◆ TryConvert() [5/13]

template<>
bool duckdb::Hugeint::TryConvert ( int64_t value,
hugeint_t & result )
122464 {
122465 result = HugeintConvertInteger<int64_t>(value);
122466 return true;
122467}

◆ TryConvert() [6/13]

template<>
bool duckdb::Hugeint::TryConvert ( uint8_t value,
hugeint_t & result )
122469 {
122470 result = HugeintConvertInteger<uint8_t>(value);
122471 return true;
122472}

◆ TryConvert() [7/13]

template<>
bool duckdb::Hugeint::TryConvert ( uint16_t value,
hugeint_t & result )
122474 {
122475 result = HugeintConvertInteger<uint16_t>(value);
122476 return true;
122477}

◆ TryConvert() [8/13]

template<>
bool duckdb::Hugeint::TryConvert ( uint32_t value,
hugeint_t & result )
122479 {
122480 result = HugeintConvertInteger<uint32_t>(value);
122481 return true;
122482}

◆ TryConvert() [9/13]

template<>
bool duckdb::Hugeint::TryConvert ( uint64_t value,
hugeint_t & result )
122484 {
122485 result = HugeintConvertInteger<uint64_t>(value);
122486 return true;
122487}

◆ TryConvert() [10/13]

template<>
bool duckdb::Hugeint::TryConvert ( hugeint_t value,
hugeint_t & result )
122490 {
122491 result = value;
122492 return true;
122493}

◆ TryConvert() [11/13]

template<>
bool duckdb::Hugeint::TryConvert ( float value,
hugeint_t & result )
122496 {
122497 return Hugeint::TryConvert(double(value), result);
122498}

◆ TryConvert() [12/13]

template<>
bool duckdb::Hugeint::TryConvert ( double value,
hugeint_t & result )
122521 {
122522 return ConvertFloatingToBigint<double>(value, result);
122523}

◆ TryConvert() [13/13]

template<>
bool duckdb::Hugeint::TryConvert ( long double value,
hugeint_t & result )
122526 {
122527 return ConvertFloatingToBigint<long double>(value, result);
122528}

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