You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
chore(datatypes): refactoring math ops results domain check functionality
This commit is contained in:
@ -21,8 +21,10 @@
|
||||
#include <cfloat>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <string>
|
||||
|
||||
#include "mcs_datatype_basic.h"
|
||||
#include "mcs_float128.h"
|
||||
|
||||
// Inline asm has three argument lists: output, input and clobber list
|
||||
@ -189,6 +191,11 @@ class TSInt128
|
||||
return s128Value == static_cast<int128_t>(x);
|
||||
}
|
||||
|
||||
inline operator bool() const
|
||||
{
|
||||
return s128Value != 0;
|
||||
}
|
||||
|
||||
inline operator double() const
|
||||
{
|
||||
return toDouble();
|
||||
@ -249,6 +256,18 @@ class TSInt128
|
||||
return static_cast<uint64_t>(s128Value);
|
||||
}
|
||||
|
||||
// This can be replaced with a template based on SQL data type
|
||||
std::optional<uint64_t> toUBIGINTWithDomainCheck() const
|
||||
{
|
||||
if (s128Value > static_cast<int128_t>(datatypes::ranges_limits<SystemCatalog::UBIGINT>::max()) ||
|
||||
s128Value < datatypes::ranges_limits<SystemCatalog::UBIGINT>::min())
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return static_cast<uint64_t>(s128Value);
|
||||
}
|
||||
|
||||
inline operator TFloat128() const
|
||||
{
|
||||
return toTFloat128();
|
||||
@ -271,6 +290,7 @@ class TSInt128
|
||||
return TSInt128(s128Value % rhs);
|
||||
}
|
||||
|
||||
// These math operators don't do out-of-range checks.
|
||||
inline TSInt128 operator*(const TSInt128& rhs) const
|
||||
{
|
||||
return TSInt128(s128Value * rhs.s128Value);
|
||||
@ -281,6 +301,16 @@ class TSInt128
|
||||
return TSInt128(s128Value + rhs.s128Value);
|
||||
}
|
||||
|
||||
inline TSInt128 operator-(const TSInt128& rhs) const
|
||||
{
|
||||
return TSInt128(s128Value - rhs.s128Value);
|
||||
}
|
||||
|
||||
inline TSInt128 operator/(const TSInt128& rhs) const
|
||||
{
|
||||
return TSInt128(s128Value / rhs.s128Value);
|
||||
}
|
||||
|
||||
inline bool operator>(const TSInt128& rhs) const
|
||||
{
|
||||
return s128Value > rhs.s128Value;
|
||||
@ -321,4 +351,3 @@ class TSInt128
|
||||
}; // end of class
|
||||
|
||||
} // end of namespace datatypes
|
||||
|
||||
|
Reference in New Issue
Block a user