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

Public Member Functions

template<>
int DecimalLength (hugeint_t value, uint8_t width, uint8_t scale)
template<>
string_t Format (hugeint_t value, uint8_t width, uint8_t scale, Vector &vector)
template<>
void FormatDecimal (hugeint_t value, uint8_t width, uint8_t scale, char *dst, idx_t len)
template<>
int DecimalLength (hugeint_t value, uint8_t width, uint8_t scale)
template<>
string_t Format (hugeint_t value, uint8_t width, uint8_t scale, Vector &vector)
template<>
void FormatDecimal (hugeint_t value, uint8_t width, uint8_t scale, char *dst, idx_t len)

Static Public Member Functions

template<class SIGNED>
static int DecimalLength (SIGNED value, uint8_t width, uint8_t scale)
template<class SIGNED>
static void FormatDecimal (SIGNED value, uint8_t width, uint8_t scale, char *dst, idx_t len)
template<class SIGNED>
static string_t Format (SIGNED value, uint8_t width, uint8_t scale, Vector &vector)

Member Function Documentation

◆ DecimalLength() [1/2]

template<class SIGNED>
int duckdb::DecimalToString::DecimalLength ( SIGNED value,
uint8_t width,
uint8_t scale )
inlinestatic
19797 {
19798 using UNSIGNED = typename MakeUnsigned<SIGNED>::type;
19799 if (scale == 0) {
19800 // scale is 0: regular number
19801 return NumericHelper::SignedLength<SIGNED, UNSIGNED>(value);
19802 }
19803 // length is max of either:
19804 // scale + 2 OR
19805 // integer length + 1
19806 // scale + 2 happens when the number is in the range of (-1, 1)
19807 // in that case we print "0.XXX", which is the scale, plus "0." (2 chars)
19808 // integer length + 1 happens when the number is outside of that range
19809 // in that case we print the integer number, but with one extra character ('.')
19810 auto extra_characters = width > scale ? 2 : 1;
19811 return MaxValue(scale + extra_characters + (value < 0 ? 1 : 0),
19812 NumericHelper::SignedLength<SIGNED, UNSIGNED>(value) + 1);
19813 }
void scale(cv::Mat &mat, const cv::Mat &range, const T min, const T max)

◆ FormatDecimal() [1/2]

template<class SIGNED>
void duckdb::DecimalToString::FormatDecimal ( SIGNED value,
uint8_t width,
uint8_t scale,
char * dst,
idx_t len )
inlinestatic
19816 {
19817 using UNSIGNED = typename MakeUnsigned<SIGNED>::type;
19818 char *end = dst + len;
19819 if (value < 0) {
19820 value = -value;
19821 *dst = '-';
19822 }
19823 if (scale == 0) {
19824 NumericHelper::FormatUnsigned<UNSIGNED>(UnsafeNumericCast<UNSIGNED>(value), end);
19825 return;
19826 }
19827 // we write two numbers:
19828 // the numbers BEFORE the decimal (major)
19829 // and the numbers AFTER the decimal (minor)
19830 auto minor =
19831 UnsafeNumericCast<UNSIGNED>(value) % UnsafeNumericCast<UNSIGNED>(NumericHelper::POWERS_OF_TEN[scale]);
19832 auto major =
19833 UnsafeNumericCast<UNSIGNED>(value) / UnsafeNumericCast<UNSIGNED>(NumericHelper::POWERS_OF_TEN[scale]);
19834 // write the number after the decimal
19835 dst = NumericHelper::FormatUnsigned<UNSIGNED>(UnsafeNumericCast<UNSIGNED>(minor), end);
19836 // (optionally) pad with zeros and add the decimal point
19837 while (dst > (end - scale)) {
19838 *--dst = '0';
19839 }
19840 *--dst = '.';
19841 // now write the part before the decimal
19842 D_ASSERT(width > scale || major == 0);
19843 if (width > scale) {
19844 // there are numbers after the comma
19845 dst = NumericHelper::FormatUnsigned<UNSIGNED>(UnsafeNumericCast<UNSIGNED>(major), dst);
19846 }
19847 }

◆ Format() [1/2]

template<class SIGNED>
string_t duckdb::DecimalToString::Format ( SIGNED value,
uint8_t width,
uint8_t scale,
Vector & vector )
inlinestatic
19850 {
19851 int len = DecimalLength<SIGNED>(value, width, scale);
19852 string_t result = StringVector::EmptyString(vector, NumericCast<size_t>(len));
19853 FormatDecimal<SIGNED>(value, width, scale, result.GetDataWriteable(), UnsafeNumericCast<idx_t>(len));
19854 result.Finalize();
19855 return result;
19856 }
static DUCKDB_API string_t EmptyString(Vector &vector, idx_t len)
Definition duckdb.cpp:137942

◆ DecimalLength() [2/2]

template<>
int duckdb::DecimalToString::DecimalLength ( hugeint_t value,
uint8_t width,
uint8_t scale )
113615 {
113616 D_ASSERT(value > NumericLimits<hugeint_t>::Minimum());
113617 int negative;
113618
113619 if (value.upper < 0) {
113620 Hugeint::NegateInPlace(value);
113621 negative = 1;
113622 } else {
113623 negative = 0;
113624 }
113625 if (scale == 0) {
113626 // scale is 0: regular number
113627 return NumericHelper::UnsignedLength(value) + negative;
113628 }
113629 // length is max of either:
113630 // scale + 2 OR
113631 // integer length + 1
113632 // scale + 2 happens when the number is in the range of (-1, 1)
113633 // in that case we print "0.XXX", which is the scale, plus "0." (2 chars)
113634 // integer length + 1 happens when the number is outside of that range
113635 // in that case we print the integer number, but with one extra character ('.')
113636 auto extra_numbers = width > scale ? 2 : 1;
113637 return MaxValue(scale + extra_numbers, NumericHelper::UnsignedLength(value) + 1) + negative;
113638}

◆ Format() [2/2]

template<>
string_t duckdb::DecimalToString::Format ( hugeint_t value,
uint8_t width,
uint8_t scale,
Vector & vector )
113641 {
113642 int length = DecimalLength(value, width, scale);
113643 string_t result = StringVector::EmptyString(vector, NumericCast<idx_t>(length));
113644
113645 auto dst = result.GetDataWriteable();
113646
113647 FormatDecimal(value, width, scale, dst, NumericCast<idx_t>(length));
113648
113649 result.Finalize();
113650 return result;
113651}

◆ FormatDecimal() [2/2]

template<>
void duckdb::DecimalToString::FormatDecimal ( hugeint_t value,
uint8_t width,
uint8_t scale,
char * dst,
idx_t len )
113681 {
113682 auto endptr = dst + len;
113683
113684 int negative = value.upper < 0;
113685 if (negative) {
113686 Hugeint::NegateInPlace(value);
113687 *dst = '-';
113688 dst++;
113689 }
113690 if (scale == 0) {
113691 // with scale=0 we format the number as a regular number
113692 NumericHelper::FormatUnsigned(value, endptr);
113693 return;
113694 }
113695
113696 // we write two numbers:
113697 // the numbers BEFORE the decimal (major)
113698 // and the numbers AFTER the decimal (minor)
113699 hugeint_t minor;
113700 hugeint_t major = Hugeint::DivMod(value, Hugeint::POWERS_OF_TEN[scale], minor);
113701
113702 // write the number after the decimal
113703 dst = NumericHelper::FormatUnsigned(minor, endptr);
113704 // (optionally) pad with zeros and add the decimal point
113705 while (dst > (endptr - scale)) {
113706 *--dst = '0';
113707 }
113708 *--dst = '.';
113709 // now write the part before the decimal
113710 D_ASSERT(width > scale || major == 0);
113711 if (width > scale) {
113712 dst = NumericHelper::FormatUnsigned(major, dst);
113713 }
113714}

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