pack(*), truncate, bug fixes
This commit is contained in:
@@ -37,6 +37,27 @@ VT<double> sqrt(const VT<T>& v) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
template <class T>
|
||||
T truncate(const T& v, const uint32_t precision) {
|
||||
auto multiplier = pow(10, precision);
|
||||
if (v >= std::numeric_limits<T>::max()/multiplier ||
|
||||
aq_fp_precision<T> <= precision)
|
||||
return v;
|
||||
else
|
||||
return round(v * multiplier)/multiplier;
|
||||
}
|
||||
template<class T, template<typename ...> class VT>
|
||||
VT<T> truncate(const VT<T>& v, const uint32_t precision) {
|
||||
if (aq_fp_precision<T> <= precision)
|
||||
return v.subvec_memcpy();
|
||||
auto multiplier = pow(10, precision);
|
||||
auto max_truncate = std::numeric_limits<T>::max()/multiplier;
|
||||
VT<T> ret{ v.size };
|
||||
for (uint32_t i = 0; i < v.size; ++i) { // round or trunc??
|
||||
ret[i] = v[i] < max_truncate ? round(v[i] * multiplier)/multiplier : v[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <class T, template<typename ...> class VT>
|
||||
T max(const VT<T>& v) {
|
||||
@@ -207,6 +228,7 @@ T first(const VT<T>& arr) {
|
||||
return arr[0];
|
||||
}
|
||||
|
||||
|
||||
#define __DEFAULT_AGGREGATE_FUNCTION__(NAME, RET) \
|
||||
template <class T> constexpr inline T NAME(const T& v) { return RET; }
|
||||
|
||||
|
||||
+10
-1
@@ -241,7 +241,16 @@ std::ostream& operator<<(std::ostream& os, types::timestamp_t & v)
|
||||
print_datetime(v);
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, int8_t & v)
|
||||
{
|
||||
os<<static_cast<int>(v);
|
||||
return os;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, uint8_t & v)
|
||||
{
|
||||
os<<static_cast<unsigned>(v);
|
||||
return os;
|
||||
}
|
||||
|
||||
std::string base62uuid(int l) {
|
||||
using namespace std;
|
||||
|
||||
@@ -46,6 +46,8 @@ std::ostream& operator<<(std::ostream& os, __int128& v);
|
||||
std::ostream& operator<<(std::ostream& os, __uint128_t& v);
|
||||
#endif
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, int8_t& v);
|
||||
std::ostream& operator<<(std::ostream& os, uint8_t& v);
|
||||
std::ostream& operator<<(std::ostream& os, types::date_t& v);
|
||||
std::ostream& operator<<(std::ostream& os, types::time_t& v);
|
||||
std::ostream& operator<<(std::ostream& os, types::timestamp_t& v);
|
||||
|
||||
+17
-4
@@ -53,12 +53,12 @@ constexpr bool aqis_same<T1, T2> = aqis_same_impl<T1, T2>::value;
|
||||
namespace types {
|
||||
enum Type_t {
|
||||
AINT32, AFLOAT, ASTR, ADOUBLE, ALDOUBLE, AINT64, AINT128, AINT16, ADATE, ATIME, AINT8,
|
||||
AUINT32, AUINT64, AUINT128, AUINT16, AUINT8, ABOOL, VECTOR, ATIMESTAMP, NONE, ERROR
|
||||
AUINT32, AUINT64, AUINT128, AUINT16, AUINT8, ABOOL, VECTOR, ATIMESTAMP, ACHAR, NONE, ERROR
|
||||
};
|
||||
static constexpr const char* printf_str[] = { "%d", "%f", "%s", "%lf", "%Lf", "%ld", "%d", "%hi", "%s", "%s", "%c",
|
||||
"%u", "%lu", "%s", "%hu", "%hhu", "%s", "%s", "Vector<%s>", "%s", "NULL", "ERROR" };
|
||||
static constexpr const char* printf_str[] = { "%d", "%f", "%s", "%lf", "%Lf", "%ld", "%d", "%hi", "%s", "%s", "%hhd",
|
||||
"%u", "%lu", "%s", "%hu", "%hhu", "%s", "%s", "Vector<%s>", "%s", "%c", "NULL", "ERROR" };
|
||||
static constexpr const char* SQL_Type[] = { "INT", "REAL", "TEXT", "DOUBLE", "DOUBLE", "BIGINT", "HUGEINT", "SMALLINT", "DATE", "TIME", "TINYINT",
|
||||
"INT", "BIGINT", "HUGEINT", "SMALLINT", "TINYINT", "BOOL", "HUGEINT", "TIMESTAMP", "NULL", "ERROR"};
|
||||
"INT", "BIGINT", "HUGEINT", "SMALLINT", "TINYINT", "BOOL", "HUGEINT", "TIMESTAMP", "CHAR", "NULL", "ERROR"};
|
||||
|
||||
|
||||
// TODO: deal with data/time <=> str/uint conversion
|
||||
@@ -434,6 +434,19 @@ struct nullval_impl<float> { constexpr static float value = -std::numeric_limits
|
||||
template<>
|
||||
struct nullval_impl<double> { constexpr static double value = -std::numeric_limits<double>::quiet_NaN(); };
|
||||
|
||||
template <class T>
|
||||
constexpr uint32_t my_rlog10_approx(T v){
|
||||
uint32_t r = 0;
|
||||
while (v + std::numeric_limits<T>::epsilon() < 1){
|
||||
v *= 10;
|
||||
r++;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
template <class T>
|
||||
inline constexpr uint32_t aq_fp_precision = std::is_floating_point_v<T> ?
|
||||
my_rlog10_approx(std::numeric_limits<T>::epsilon()) : 0;
|
||||
|
||||
constexpr size_t sum_type(size_t a[], size_t sz) {
|
||||
size_t ret = 0;
|
||||
for (int i = 0; i < sz; ++i)
|
||||
|
||||
@@ -290,8 +290,8 @@ public:
|
||||
return subvec;
|
||||
}
|
||||
inline vector_type<_Ty> subvec(uint32_t start = 0) { return subvec(start, size); }
|
||||
inline vector_type<_Ty> subvec_memcpy(uint32_t start = 0) { return subvec_memcpy(start, size); }
|
||||
inline vector_type<_Ty> subvec_deep(uint32_t start = 0) { return subvec_deep(start, size); }
|
||||
inline vector_type<_Ty> subvec_memcpy(uint32_t start = 0) const { return subvec_memcpy(start, size); }
|
||||
inline vector_type<_Ty> subvec_deep(uint32_t start = 0) const { return subvec_deep(start, size); }
|
||||
vector_type<_Ty> getRef() { return vector_type<_Ty>(container, size); }
|
||||
~vector_type() {
|
||||
if (capacity > 0) free(container);
|
||||
|
||||
Reference in New Issue
Block a user