diff --git a/source/object/object.cpp b/source/object/object.cpp index 0e60038..d32b473 100644 --- a/source/object/object.cpp +++ b/source/object/object.cpp @@ -51,12 +51,18 @@ auto are_almost_equal(double a, double b) -> bool template auto eq_helper(const T* t, const object& other) -> const object* { + if constexpr (std::is_same_v) { + return native_bool_to_object(other.is(t->type()) && are_almost_equal(t->value, other.val())); + } return native_bool_to_object(other.is(t->type()) && t->value == other.as()->value); } template auto value_eq_helper(const T& lhs, const T& rhs) -> const object* { + if constexpr (std::is_same_v) { + return native_bool_to_object(are_almost_equal(lhs, rhs)); + } return native_bool_to_object(lhs == rhs); } @@ -66,18 +72,6 @@ auto value_gt_helper(const T& lhs, const T& rhs) -> const object* return native_bool_to_object(lhs > rhs); } -template<> -auto value_eq_helper(const double& lhs, const double& rhs) -> const object* -{ - return native_bool_to_object(are_almost_equal(lhs, rhs)); -} - -template<> -auto eq_helper(const decimal_object* t, const object& other) -> const object* -{ - return native_bool_to_object(other.is(t->type()) && are_almost_equal(t->value, other.val())); -} - template auto gt_helper(const T* t, const object& other) -> const object* { @@ -260,10 +254,10 @@ auto boolean_object::operator>(const object& other) const -> const object* auto boolean_object::operator+(const object& other) const -> const object* { if (other.is(integer)) { - return make(value_to() + other.val()); + return other + *this; } if (other.is(decimal)) { - return make(value_to() + other.val()); + return other + *this; } if (other.is(boolean)) { return make(value_to() @@ -351,8 +345,7 @@ auto boolean_object::operator%(const object& other) const -> const object* auto boolean_object::operator&(const object& other) const -> const object* { if (other.is(boolean)) { - return make( - ((static_cast(value) & static_cast(other.as()->value)) != 0)); + return make(value & other.val()); } if (other.is(integer)) { return other & *this; @@ -363,8 +356,7 @@ auto boolean_object::operator&(const object& other) const -> const object* auto boolean_object::operator|(const object& other) const -> const object* { if (other.is(boolean)) { - return make( - ((static_cast(value) | static_cast(other.as()->value)) != 0)); + return make(value | other.val()); } if (other.is(integer)) { return other | *this; @@ -375,8 +367,7 @@ auto boolean_object::operator|(const object& other) const -> const object* auto boolean_object::operator^(const object& other) const -> const object* { if (other.is(boolean)) { - return make( - ((static_cast(value) ^ static_cast(other.as()->value)) != 0)); + return make(value ^ other.val()); } if (other.is(integer)) { return other ^ *this; @@ -387,8 +378,7 @@ auto boolean_object::operator^(const object& other) const -> const object* auto boolean_object::operator<<(const object& other) const -> const object* { if (other.is(boolean)) { - return make(static_cast(value) - << static_cast(other.as()->value)); + return make(value_to() << other.val()); } if (other.is(integer)) { return make(value_to() << other.val()); @@ -399,8 +389,7 @@ auto boolean_object::operator<<(const object& other) const -> const object* auto boolean_object::operator>>(const object& other) const -> const object* { if (other.is(boolean)) { - return make(static_cast(value) - >> static_cast(other.as()->value)); + return make(value_to() >> other.val()); } if (other.is(integer)) { return make(value_to() >> other.val()); @@ -685,7 +674,7 @@ auto decimal_object::operator>(const object& other) const -> const object* auto object_floor_div(const object* lhs, const object* rhs) -> const object* { const auto* div = (*lhs / *rhs); - if (div->is(object::object_type::decimal)) { + if (div->is(decimal)) { return make(std::floor(div->val())); } return div; diff --git a/source/object/object.hpp b/source/object/object.hpp index 619708f..ba23063 100644 --- a/source/object/object.hpp +++ b/source/object/object.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include