Repository: incubator-quickstep Updated Branches: refs/heads/decimal-type 889c4805e -> 0acaf423a
New fixes. Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/0acaf423 Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/0acaf423 Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/0acaf423 Branch: refs/heads/decimal-type Commit: 0acaf423a9fdfaf1d140252f55d824cc7457db65 Parents: 889c480 Author: Hakan Memisoglu <hakanmemiso...@apache.org> Authored: Mon Jun 20 16:24:48 2016 -0500 Committer: Hakan Memisoglu <hakanmemiso...@apache.org> Committed: Mon Jun 20 16:24:48 2016 -0500 ---------------------------------------------------------------------- types/DecimalLit.hpp | 80 ++++++++++---------- types/DecimalType.cpp | 8 +- types/DecimalType.hpp | 2 +- .../ArithmeticBinaryOperators.hpp | 20 ++--- .../comparisons/LiteralComparators.hpp | 24 +++--- 5 files changed, 67 insertions(+), 67 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0acaf423/types/DecimalLit.hpp ---------------------------------------------------------------------- diff --git a/types/DecimalLit.hpp b/types/DecimalLit.hpp index c16a0f2..5d7b4a5 100644 --- a/types/DecimalLit.hpp +++ b/types/DecimalLit.hpp @@ -36,6 +36,40 @@ struct DecimalLit { **/ typedef std::int64_t data_type; + DecimalLit() = default; + + explicit DecimalLit(const int value) + : data_(static_cast<data_type>(value * kMaxFractionInt)) { + } + + explicit DecimalLit(const long value) + : data_(static_cast<data_type>(value * kMaxFractionInt)) { + } + + explicit DecimalLit(const float value) + : data_(static_cast<data_type>(value * kMaxFractionInt)) { + } + + explicit DecimalLit(const double value) + : data_(static_cast<data_type>(value * kMaxFractionInt)) { + } + + inline explicit operator int() const { + return static_cast<int>(getIntegerPart()); + } + + inline explicit operator long() const { + return static_cast<long>(getIntegerPart()); + } + + inline explicit operator float() const { + return static_cast<float>(data_) / kMaxFractionInt; + } + + inline explicit operator double() const { + return static_cast<double>(data_) / kMaxFractionInt; + } + /** * @brief Builder for DecimalLit. * @@ -43,9 +77,9 @@ struct DecimalLit { * the DecimalLit. * @return The resulting DecimalLit converted from the floating point. **/ - static DecimalLit fromDouble(const double value) { - return DecimalLit{static_cast<data_type>(value * kMaxFractionInt)}; - } + //static DecimalLit fromDouble(const double value) { + // return DecimalLit{static_cast<data_type>(value * kMaxFractionInt)}; + //} /** * @brief Builder for DecimalLit. @@ -54,9 +88,9 @@ struct DecimalLit { * the DecimalLit. * @return The resulting DecimalLit conveted from the integer number. **/ - static DecimalLit fromInt(const int64_t value) { - return DecimalLit{static_cast<data_type>(value * kMaxFractionInt)}; - } + //static DecimalLit fromInt(const int64_t value) { + // return DecimalLit{static_cast<data_type>(value * kMaxFractionInt)}; + //} data_type data_; @@ -257,40 +291,6 @@ struct DecimalLit { data_ = (data_ * kMaxFractionInt) / other.data_; return *this; } - - inline explicit operator int() const { - return static_cast<int>(getIntegerPart()); - } - - inline explicit operator long() const { - return static_cast<long>(getIntegerPart()); - } - - inline explicit operator double() const { - return static_cast<double>(data_) / kMaxFractionInt; - } - - inline explicit operator float() const { - return static_cast<float>(data_) / kMaxFractionInt; - } - - DecimalLit() = default; - - explicit DecimalLit(const int value) - : data_(static_cast<data_type>(value * kMaxFractionInt)) { - } - - explicit DecimalLit(const long value) - : data_(static_cast<data_type>(value * kMaxFractionInt)) { - } - - explicit DecimalLit(const float value) - : data_(static_cast<data_type>(value * kMaxFractionInt)) { - } - - explicit DecimalLit(const double value) - : data_(static_cast<data_type>(value * kMaxFractionInt)) { - } }; //** @} */ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0acaf423/types/DecimalType.cpp ---------------------------------------------------------------------- diff --git a/types/DecimalType.cpp b/types/DecimalType.cpp index 31ca76d..71283e3 100644 --- a/types/DecimalType.cpp +++ b/types/DecimalType.cpp @@ -56,11 +56,11 @@ TypedValue DecimalType::coerceValue(const TypedValue &original_value, switch (original_type.getTypeID()) { case kInt: - return TypedValue(DecimalLit::fromInt(original_value.getLiteral<int>())); + return TypedValue(DecimalLit(original_value.getLiteral<int>())); case kLong: - return TypedValue(DecimalLit::fromInt(original_value.getLiteral<std::int64_t>())); + return TypedValue(DecimalLit(original_value.getLiteral<std::int64_t>())); case kFloat: - return TypedValue(DecimalLit::fromDouble(original_value.getLiteral<float>())); + return TypedValue(DecimalLit(original_value.getLiteral<float>())); case kDouble: return original_value; default: @@ -110,7 +110,7 @@ bool DecimalType::parseValueFromString(const std::string &value_string, return false; } - *value = TypedValue(DecimalLit::fromDouble(parsed_double)); + *value = TypedValue(DecimalLit(parsed_double)); return true; } http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0acaf423/types/DecimalType.hpp ---------------------------------------------------------------------- diff --git a/types/DecimalType.hpp b/types/DecimalType.hpp index 68a204f..27ba2c1 100644 --- a/types/DecimalType.hpp +++ b/types/DecimalType.hpp @@ -98,7 +98,7 @@ class DecimalType : public NumericSuperType<DecimalLit> { const Type &original_type) const override; TypedValue makeZeroValue() const override { - return TypedValue(DecimalLit::fromInt(0)); + return TypedValue(DecimalLit(0)); } private: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0acaf423/types/operations/binary_operations/ArithmeticBinaryOperators.hpp ---------------------------------------------------------------------- diff --git a/types/operations/binary_operations/ArithmeticBinaryOperators.hpp b/types/operations/binary_operations/ArithmeticBinaryOperators.hpp index 8414da7..408a16b 100644 --- a/types/operations/binary_operations/ArithmeticBinaryOperators.hpp +++ b/types/operations/binary_operations/ArithmeticBinaryOperators.hpp @@ -86,14 +86,14 @@ struct AddFunctor<DecimalLit, DecimalLit> { template <typename RightArgument> struct AddFunctor<DecimalLit, RightArgument> { inline DecimalLit operator() (const DecimalLit &left, const RightArgument &right) const { - return left + DecimalLit::fromDouble(static_cast<double>(right)); + return left + DecimalLit(right); } }; template <typename LeftArgument> struct AddFunctor<LeftArgument, DecimalLit> { inline DecimalLit operator() (const LeftArgument &left, const DecimalLit &right) const { - return DecimalLit::fromDouble(static_cast<double>(left)) + right; + return DecimalLit(left) + right; } }; @@ -130,14 +130,14 @@ struct SubtractFunctor<DecimalLit, DecimalLit> { template <typename RightArgument> struct SubtractFunctor<DecimalLit, RightArgument> { inline DecimalLit operator() (const DecimalLit &left, const RightArgument &right) const { - return left - DecimalLit::fromDouble(static_cast<double>(right)); + return left - DecimalLit(right); } }; template <typename LeftArgument> struct SubtractFunctor<LeftArgument, DecimalLit> { inline DecimalLit operator() (const LeftArgument &left, const DecimalLit &right) const { - return DecimalLit::fromDouble(static_cast<double>(left)) - right; + return DecimalLit(left) - right; } }; @@ -174,14 +174,14 @@ struct MultiplyFunctor<DecimalLit, DecimalLit> { template <typename RightArgument> struct MultiplyFunctor<DecimalLit, RightArgument> { inline DecimalLit operator() (const DecimalLit &left, const RightArgument &right) const { - return left * DecimalLit::fromDouble(static_cast<double>(right)); + return left * DecimalLit(right); } }; template <typename LeftArgument> struct MultiplyFunctor<LeftArgument, DecimalLit> { inline DecimalLit operator() (const LeftArgument &left, const DecimalLit &right) const { - return DecimalLit::fromDouble(static_cast<double>(left)) * right; + return DecimalLit(left) * right; } }; @@ -218,14 +218,14 @@ struct DivideFunctor<DecimalLit, DecimalLit> { template <typename RightArgument> struct DivideFunctor<DecimalLit, RightArgument> { inline DecimalLit operator() (const DecimalLit &left, const RightArgument &right) const { - return left / DecimalLit::fromDouble(static_cast<double>(right)); + return left / DecimalLit(right); } }; template <typename LeftArgument> struct DivideFunctor<LeftArgument, DecimalLit> { inline DecimalLit operator() (const LeftArgument &left, const DecimalLit &right) const { - return DecimalLit::fromDouble(static_cast<double>(left)) / right; + return DecimalLit(left) / right; } }; @@ -257,14 +257,14 @@ struct FloatModuloFunctor<DecimalLit, DecimalLit> { template <typename RightArgument> struct FloatModuloFunctor<DecimalLit, RightArgument> { inline DecimalLit operator() (const DecimalLit &left, const RightArgument &right) const { - return left % DecimalLit::fromDouble(static_cast<double>(right)); + return left % DecimalLit(right); } }; template <typename LeftArgument> struct FloatModuloFunctor<LeftArgument, DecimalLit> { inline DecimalLit operator() (const LeftArgument &left, const DecimalLit &right) const { - return DecimalLit::fromDouble(static_cast<double>(left)) % right; + return DecimalLit(left) % right; } }; http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0acaf423/types/operations/comparisons/LiteralComparators.hpp ---------------------------------------------------------------------- diff --git a/types/operations/comparisons/LiteralComparators.hpp b/types/operations/comparisons/LiteralComparators.hpp index c5ea1e0..d009b23 100644 --- a/types/operations/comparisons/LiteralComparators.hpp +++ b/types/operations/comparisons/LiteralComparators.hpp @@ -55,14 +55,14 @@ template <> struct EqualFunctor<DecimalLit, DecimalLit> template <typename RightArgument> struct EqualFunctor<DecimalLit, RightArgument> : public std::binary_function<DecimalLit, RightArgument, bool> { inline bool operator() (const DecimalLit &left, const RightArgument &right) const { - return left == DecimalLit::fromDouble(static_cast<double>(right)); + return left == DecimalLit(right); } }; template <typename LeftArgument> struct EqualFunctor<LeftArgument, DecimalLit> : public std::binary_function<LeftArgument, DecimalLit, bool> { inline bool operator() (const LeftArgument &left, const DecimalLit &right) const { - return DecimalLit::fromDouble(static_cast<double>(left)) == right; + return DecimalLit(left) == right; } }; @@ -83,14 +83,14 @@ template <> struct NotEqualFunctor<DecimalLit, DecimalLit> template <typename RightArgument> struct NotEqualFunctor<DecimalLit, RightArgument> : public std::binary_function<DecimalLit, RightArgument, bool> { inline bool operator() (const DecimalLit &left, const RightArgument &right) const { - return left != DecimalLit::fromDouble(right); + return left != DecimalLit(right); } }; template <typename LeftArgument> struct NotEqualFunctor<LeftArgument, DecimalLit> : public std::binary_function<LeftArgument, DecimalLit, bool> { inline bool operator() (const LeftArgument &left, const DecimalLit &right) const { - return DecimalLit::fromDouble(left) != right; + return DecimalLit(left) != right; } }; @@ -111,14 +111,14 @@ template <> struct LessFunctor<DecimalLit, DecimalLit> template <typename RightArgument> struct LessFunctor<DecimalLit, RightArgument> : public std::binary_function<DecimalLit, RightArgument, bool> { inline bool operator() (const DecimalLit &left, const RightArgument &right) const { - return left < DecimalLit::fromDouble(static_cast<double>(right)); + return left < DecimalLit(right); } }; template <typename LeftArgument> struct LessFunctor<LeftArgument, DecimalLit> : public std::binary_function<LeftArgument, DecimalLit, bool> { inline bool operator() (const LeftArgument &left, const DecimalLit &right) const { - return DecimalLit::fromDouble(static_cast<double>(left)) < right; + return DecimalLit(left) < right; } }; @@ -139,14 +139,14 @@ template <> struct LessOrEqualFunctor<DecimalLit, DecimalLit> template <typename RightArgument> struct LessOrEqualFunctor<DecimalLit, RightArgument> : public std::binary_function<DecimalLit, RightArgument, bool> { inline bool operator() (const DecimalLit &left, const RightArgument &right) const { - return left <= DecimalLit::fromDouble(static_cast<double>(right)); + return left <= DecimalLit(right); } }; template <typename LeftArgument> struct LessOrEqualFunctor<LeftArgument, DecimalLit> : public std::binary_function<LeftArgument, DecimalLit, bool> { inline bool operator() (const LeftArgument &left, const DecimalLit &right) const { - return DecimalLit::fromDouble(static_cast<double>(left)) <= right; + return DecimalLit(left) <= right; } }; @@ -167,14 +167,14 @@ template <> struct GreaterFunctor<DecimalLit, DecimalLit> template <typename RightArgument> struct GreaterFunctor<DecimalLit, RightArgument> : public std::binary_function<DecimalLit, RightArgument, bool> { inline bool operator() (const DecimalLit &left, const RightArgument &right) const { - return left > DecimalLit::fromDouble(static_cast<double>(right)); + return left > DecimalLit(right); } }; template <typename LeftArgument> struct GreaterFunctor<LeftArgument, DecimalLit> : public std::binary_function<LeftArgument, DecimalLit, bool> { inline bool operator() (const LeftArgument &left, const DecimalLit &right) const { - return DecimalLit::fromDouble(static_cast<double>(left)) > right; + return DecimalLit(left) > right; } }; @@ -195,14 +195,14 @@ template <> struct GreaterOrEqualFunctor<DecimalLit, DecimalLit> template <typename RightArgument> struct GreaterOrEqualFunctor<DecimalLit, RightArgument> : public std::binary_function<DecimalLit, RightArgument, bool> { inline bool operator() (const DecimalLit &left, const RightArgument &right) const { - return left >= DecimalLit::fromDouble(static_cast<double>(right)); + return left >= DecimalLit(right); } }; template <typename LeftArgument> struct GreaterOrEqualFunctor<LeftArgument, DecimalLit> : public std::binary_function<LeftArgument, DecimalLit, bool> { inline bool operator() (const LeftArgument &left, const DecimalLit &right) const { - return DecimalLit::fromDouble(static_cast<double>(left)) >= right; + return DecimalLit(left) >= right; } };