From f76a8e86807d36ba913c39d8b143d9573981c991 Mon Sep 17 00:00:00 2001 From: fintarin Date: Fri, 5 Apr 2024 22:41:46 +0400 Subject: [PATCH 1/3] Remove IInteger --- include/fintamath/numbers/IInteger.hpp | 183 ------------- include/fintamath/numbers/IIntegerCRTP.hpp | 220 ---------------- include/fintamath/numbers/Integer.hpp | 148 ++++++++++- src/fintamath/config/TypeConfig.cpp | 5 +- src/fintamath/numbers/IInteger.cpp | 7 - src/fintamath/numbers/Integer.cpp | 83 +++++- src/fintamath/numbers/NumberAbstract.cpp | 5 +- tests/src/numbers/IIntegerTests.cpp | 291 --------------------- tests/src/numbers/IntegerTests.cpp | 2 +- 9 files changed, 218 insertions(+), 726 deletions(-) delete mode 100644 include/fintamath/numbers/IInteger.hpp delete mode 100644 include/fintamath/numbers/IIntegerCRTP.hpp delete mode 100644 src/fintamath/numbers/IInteger.cpp delete mode 100644 tests/src/numbers/IIntegerTests.cpp diff --git a/include/fintamath/numbers/IInteger.hpp b/include/fintamath/numbers/IInteger.hpp deleted file mode 100644 index 93f4fe2db..000000000 --- a/include/fintamath/numbers/IInteger.hpp +++ /dev/null @@ -1,183 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/core/Parser.hpp" -#include "fintamath/numbers/INumber.hpp" - -namespace fintamath { - -class IInteger : public INumber { - FINTAMATH_PARENT_CLASS_BODY(IInteger) - -public: - friend std::unique_ptr operator%(const IInteger &lhs, const IInteger &rhs) { - return lhs.modAbstract(rhs); - } - - friend std::unique_ptr operator&(const IInteger &lhs, const IInteger &rhs) { - return lhs.bitAndAbstract(rhs); - } - - friend std::unique_ptr operator|(const IInteger &lhs, const IInteger &rhs) { - return lhs.bitOrAbstract(rhs); - } - - friend std::unique_ptr operator^(const IInteger &lhs, const IInteger &rhs) { - return lhs.bitXorAbstract(rhs); - } - - friend std::unique_ptr operator<<(const IInteger &lhs, const IInteger &rhs) { - return lhs.bitLeftShiftAbstract(rhs); - } - - friend std::unique_ptr operator>>(const IInteger &lhs, const IInteger &rhs) { - return lhs.bitRightShiftAbstract(rhs); - } - - friend std::unique_ptr operator~(const IInteger &rhs) { - return rhs.bitNotAbstract(); - } - - friend IInteger &operator++(IInteger &rhs) { - return rhs.increaseAbstract(); - } - - friend IInteger &operator--(IInteger &rhs) { - return rhs.decreaseAbstract(); - } - - friend std::unique_ptr operator++(IInteger &lhs, int) { - auto res = cast(lhs.clone()); - lhs.increaseAbstract(); - return res; - } - - friend std::unique_ptr operator--(IInteger &lhs, int) { - auto res = cast(lhs.clone()); - lhs.decreaseAbstract(); - return res; - } - -protected: - virtual std::unique_ptr modAbstract(const IInteger &rhs) const = 0; - - virtual std::unique_ptr bitAndAbstract(const IInteger &rhs) const = 0; - - virtual std::unique_ptr bitOrAbstract(const IInteger &rhs) const = 0; - - virtual std::unique_ptr bitXorAbstract(const IInteger &rhs) const = 0; - - virtual std::unique_ptr bitLeftShiftAbstract(const IInteger &rhs) const = 0; - - virtual std::unique_ptr bitRightShiftAbstract(const IInteger &rhs) const = 0; - - virtual std::unique_ptr bitNotAbstract() const = 0; - - virtual IInteger &increaseAbstract() = 0; - - virtual IInteger &decreaseAbstract() = 0; -}; - -template -class IIntegerCRTP : public IInteger { -#define I_INTEGER_CRTP IIntegerCRTP -#include "fintamath/numbers/IIntegerCRTP.hpp" -#undef I_INTEGER_CRTP -}; - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator%=(Lhs &lhs, const Rhs &rhs) { - return lhs %= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator&=(Lhs &lhs, const Rhs &rhs) { - return lhs &= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator|=(Lhs &lhs, const Rhs &rhs) { - return lhs |= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator^=(Lhs &lhs, const Rhs &rhs) { - return lhs ^= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator<<=(Lhs &lhs, const Rhs &rhs) { - return lhs <<= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs &operator>>=(Lhs &lhs, const Rhs &rhs) { - return lhs >>= Lhs(rhs); -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator%(const Lhs &lhs, const Rhs &rhs) { - return lhs % Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator%(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) % rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator&(const Lhs &lhs, const Rhs &rhs) { - return lhs & Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator&(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) & rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator|(const Lhs &lhs, const Rhs &rhs) { - return lhs | Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator|(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) | rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator^(const Lhs &lhs, const Rhs &rhs) { - return lhs ^ Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator^(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) ^ rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator<<(const Lhs &lhs, const Rhs &rhs) { - return lhs << Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator<<(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) << rhs; -} - -template Lhs, ConvertibleToAndNotSameAs Rhs> -Lhs operator>>(const Lhs &lhs, const Rhs &rhs) { - return lhs >> Lhs(rhs); -} - -template Rhs, ConvertibleToAndNotSameAs Lhs> -Rhs operator>>(const Lhs &lhs, const Rhs &rhs) { - return Rhs(lhs) >> rhs; -} - -} diff --git a/include/fintamath/numbers/IIntegerCRTP.hpp b/include/fintamath/numbers/IIntegerCRTP.hpp deleted file mode 100644 index 2bb9c02d7..000000000 --- a/include/fintamath/numbers/IIntegerCRTP.hpp +++ /dev/null @@ -1,220 +0,0 @@ -#if !defined(I_INTEGER_CRTP) && !defined(NDEBUG) - -#include "fintamath/numbers/IInteger.hpp" - -namespace fintamath { - -template -class IIntegerCRTP_ : public IInteger { - -#endif // I_INTEGER_CRTP - -#define I_NUMBER_CRTP I_INTEGER_CRTP -#include "fintamath/numbers/INumberCRTP.hpp" -#undef I_NUMBER_CRTP - -public: - Derived &operator%=(const Derived &rhs) { - return mod(rhs); - } - - Derived operator%(const Derived &rhs) const { - return Derived(cast(*this)) %= rhs; - } - - Derived &operator&=(const Derived &rhs) { - return bitAnd(rhs); - } - - Derived operator&(const Derived &rhs) const { - return Derived(cast(*this)) &= rhs; - } - - Derived &operator|=(const Derived &rhs) { - return bitOr(rhs); - } - - Derived operator|(const Derived &rhs) const { - return Derived(cast(*this)) |= rhs; - } - - Derived &operator^=(const Derived &rhs) { - return bitXor(rhs); - } - - Derived operator^(const Derived &rhs) const { - return Derived(cast(*this)) ^= rhs; - } - - Derived &operator<<=(const Derived &rhs) { - return bitLeftShift(rhs); - } - - Derived operator<<(const Derived &rhs) const { - return Derived(cast(*this)) <<= rhs; - } - - Derived &operator>>=(const Derived &rhs) { - return bitRightShift(rhs); - } - - Derived operator>>(const Derived &rhs) const { - return Derived(cast(*this)) >>= rhs; - } - - Derived operator~() const { - Derived tmp = Derived(cast(*this)); - return cast(tmp).bitNot(); - } - - Derived &operator++() { - return increase(); - } - - Derived &operator--() { - return decrease(); - } - - Derived operator++(int) { - auto res = Derived(cast(*this)); - increase(); - return res; - } - - Derived operator--(int) { - auto res = Derived(cast(*this)); - decrease(); - return res; - } - -protected: - virtual Derived &mod(const Derived &rhs) = 0; - - virtual Derived &bitAnd(const Derived &rhs) = 0; - - virtual Derived &bitOr(const Derived &rhs) = 0; - - virtual Derived &bitXor(const Derived &rhs) = 0; - - virtual Derived &bitLeftShift(const Derived &rhs) = 0; - - virtual Derived &bitRightShift(const Derived &rhs) = 0; - - virtual Derived &bitNot() = 0; - - virtual Derived &increase() = 0; - - virtual Derived &decrease() = 0; - - std::unique_ptr modAbstract(const IInteger &inRhs) const override { - return executeAbstract( - "%", inRhs, - [](I_INTEGER_CRTP &lhs, const Derived &rhs) { - return lhs.mod(rhs); - }, - [](const IInteger &lhs, const IInteger &rhs) { - return lhs % rhs; - }); - } - - std::unique_ptr bitAndAbstract(const IInteger &inRhs) const override { - return executeAbstract( - "&", inRhs, - [](I_INTEGER_CRTP &lhs, const Derived &rhs) { - return lhs.bitAnd(rhs); - }, - [](const IInteger &lhs, const IInteger &rhs) { - return lhs & rhs; - }); - } - - std::unique_ptr bitOrAbstract(const IInteger &inRhs) const override { - return executeAbstract( - "|", inRhs, - [](I_INTEGER_CRTP &lhs, const Derived &rhs) { - return lhs.bitOr(rhs); - }, - [](const IInteger &lhs, const IInteger &rhs) { - return lhs | rhs; - }); - } - - std::unique_ptr bitXorAbstract(const IInteger &inRhs) const override { - return executeAbstract( - "^", inRhs, - [](I_INTEGER_CRTP &lhs, const Derived &rhs) { - return lhs.bitXor(rhs); - }, - [](const IInteger &lhs, const IInteger &rhs) { - return lhs ^ rhs; - }); - } - - std::unique_ptr bitLeftShiftAbstract(const IInteger &inRhs) const override { - return executeAbstract( - "<<", inRhs, - [](I_INTEGER_CRTP &lhs, const Derived &rhs) { - return lhs.bitLeftShift(rhs); - }, - [](const IInteger &lhs, const IInteger &rhs) { - return lhs << rhs; - }); - } - - std::unique_ptr bitRightShiftAbstract(const IInteger &inRhs) const override { - return executeAbstract( - ">>", inRhs, - [](I_INTEGER_CRTP &lhs, const Derived &rhs) { - return lhs.bitRightShift(rhs); - }, - [](const IInteger &lhs, const IInteger &rhs) { - return lhs >> rhs; - }); - } - - std::unique_ptr bitNotAbstract() const override { - return std::make_unique(~(*this)); - } - - IInteger &increaseAbstract() override { - increase(); - return *this; - } - - IInteger &decreaseAbstract() override { - decrease(); - return *this; - } - -private: - std::unique_ptr executeAbstract(const std::string &operStr, - const IInteger &rhs, - std::invocable auto callFunc, - std::invocable auto callOper) const { - - if (const auto *rhsPtr = cast(&rhs)) { - auto lhsPtr = cast(clone()); - auto res = callFunc(*lhsPtr, *rhsPtr); - return cast(res.toMinimalObject()); - } - - if (const auto rhsPtr = cast(convert(*this, rhs))) { - auto lhsPtr = cast(clone()); - auto res = callFunc(*lhsPtr, *rhsPtr); - return cast(res.toMinimalObject()); - } - - if (const auto lhsPtr = cast(convert(rhs, *this))) { - auto res = callOper(*lhsPtr, rhs); - return cast(res->toMinimalObject()); - } - - throw InvalidInputBinaryOperatorException(operStr, toString(), rhs.toString()); - } - -private: -#if !defined(I_INTEGER_CRTP) && !defined(NDEBUG) -}; -} - -#endif // I_INTEGER_CRTP diff --git a/include/fintamath/numbers/Integer.hpp b/include/fintamath/numbers/Integer.hpp index 22690e45a..27e13929b 100644 --- a/include/fintamath/numbers/Integer.hpp +++ b/include/fintamath/numbers/Integer.hpp @@ -12,11 +12,11 @@ #include "fintamath/core/IArithmetic.hpp" #include "fintamath/core/MathObjectClass.hpp" -#include "fintamath/numbers/IInteger.hpp" +#include "fintamath/numbers/INumber.hpp" namespace fintamath { -class Integer final : public IIntegerCRTP { +class Integer final : public INumberCRTP { FINTAMATH_CLASS_BODY(Integer) public: @@ -45,6 +45,40 @@ class Integer final : public IIntegerCRTP { return backend.convert_to(); } + Integer &operator%=(const Integer &rhs); + + Integer &operator&=(const Integer &rhs); + + Integer &operator|=(const Integer &rhs); + + Integer &operator^=(const Integer &rhs); + + Integer &operator<<=(const Integer &rhs); + + Integer &operator>>=(const Integer &rhs); + + Integer operator%(const Integer &rhs) const; + + Integer operator&(const Integer &rhs) const; + + Integer operator|(const Integer &rhs) const; + + Integer operator^(const Integer &rhs) const; + + Integer operator<<(const Integer &rhs) const; + + Integer operator>>(const Integer &rhs) const; + + Integer operator~() const; + + Integer &operator++(); + + Integer &operator--(); + + Integer operator++(int); + + Integer operator--(int); + protected: bool equals(const Integer &rhs) const override; @@ -62,30 +96,120 @@ class Integer final : public IIntegerCRTP { std::unique_ptr divideAbstract(const IArithmetic &rhs) const override; - Integer &mod(const Integer &rhs) override; + Integer &negate() override; - Integer &bitAnd(const Integer &rhs) override; + Integer &mod(const Integer &rhs); - Integer &bitOr(const Integer &rhs) override; + Integer &bitAnd(const Integer &rhs); - Integer &bitXor(const Integer &rhs) override; + Integer &bitOr(const Integer &rhs); - Integer &bitLeftShift(const Integer &rhs) override; + Integer &bitXor(const Integer &rhs); - Integer &bitRightShift(const Integer &rhs) override; + Integer &bitLeftShift(const Integer &rhs); - Integer &bitNot() override; + Integer &bitRightShift(const Integer &rhs); - Integer &negate() override; + Integer &bitNot(); - Integer &increase() override; + Integer &increase(); - Integer &decrease() override; + Integer &decrease(); private: Backend backend; }; +template Rhs> +Integer &operator%=(Integer &lhs, const Rhs &rhs) { + return lhs %= Integer(rhs); +} + +template Rhs> +Integer &operator&=(Integer &lhs, const Rhs &rhs) { + return lhs &= Integer(rhs); +} + +template Rhs> +Integer &operator|=(Integer &lhs, const Rhs &rhs) { + return lhs |= Integer(rhs); +} + +template Rhs> +Integer &operator^=(Integer &lhs, const Rhs &rhs) { + return lhs ^= Integer(rhs); +} + +template Rhs> +Integer &operator<<=(Integer &lhs, const Rhs &rhs) { + return lhs <<= Integer(rhs); +} + +template Rhs> +Integer &operator>>=(Integer &lhs, const Rhs &rhs) { + return lhs >>= Integer(rhs); +} + +template Rhs> +Integer operator%(const Integer &lhs, const Rhs &rhs) { + return lhs % Integer(rhs); +} + +template Lhs> +Integer operator%(const Lhs &lhs, const Integer &rhs) { + return Integer(lhs) % rhs; +} + +template Rhs> +Integer operator&(const Integer &lhs, const Rhs &rhs) { + return lhs & Integer(rhs); +} + +template Lhs> +Integer operator&(const Lhs &lhs, const Integer &rhs) { + return Integer(lhs) & rhs; +} + +template Rhs> +Integer operator|(const Integer &lhs, const Rhs &rhs) { + return lhs | Integer(rhs); +} + +template Lhs> +Integer operator|(const Lhs &lhs, const Integer &rhs) { + return Integer(lhs) | rhs; +} + +template Rhs> +Integer operator^(const Integer &lhs, const Rhs &rhs) { + return lhs ^ Integer(rhs); +} + +template Lhs> +Integer operator^(const Lhs &lhs, const Integer &rhs) { + return Integer(lhs) ^ rhs; +} + +template Rhs> +Integer operator<<(const Integer &lhs, const Rhs &rhs) { + return lhs << Integer(rhs); +} + +template Lhs> +Integer operator<<(const Lhs &lhs, const Integer &rhs) { + return Integer(lhs) << rhs; +} + +template Rhs> +Integer operator>>(const Integer &lhs, const Rhs &rhs) { + return lhs >> Integer(rhs); +} + +template Lhs> +Integer operator>>(const Lhs &lhs, const Integer &rhs) { + return Integer(lhs) >> rhs; +} + } template <> diff --git a/src/fintamath/config/TypeConfig.cpp b/src/fintamath/config/TypeConfig.cpp index c59f312b4..cdfa74557 100644 --- a/src/fintamath/config/TypeConfig.cpp +++ b/src/fintamath/config/TypeConfig.cpp @@ -111,7 +111,6 @@ #include "fintamath/literals/constants/Pi.hpp" #include "fintamath/literals/constants/True.hpp" #include "fintamath/literals/constants/Undefined.hpp" -#include "fintamath/numbers/IInteger.hpp" #include "fintamath/numbers/INumber.hpp" #include "fintamath/numbers/Integer.hpp" #include "fintamath/numbers/Rational.hpp" @@ -128,13 +127,11 @@ TypeConfig::TypeConfig() { IComparable::registerType(); - INumber::registerType(); + INumber::registerType(); INumber::registerType(); INumber::registerType(); INumber::registerType(); - IInteger::registerType(); - ILiteral::registerType(); ILiteral::registerType(); ILiteral::registerType(); diff --git a/src/fintamath/numbers/IInteger.cpp b/src/fintamath/numbers/IInteger.cpp deleted file mode 100644 index e3f972ec4..000000000 --- a/src/fintamath/numbers/IInteger.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "fintamath/numbers/IInteger.hpp" - -namespace fintamath { - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IInteger) - -} diff --git a/src/fintamath/numbers/Integer.cpp b/src/fintamath/numbers/Integer.cpp index 52aba98eb..6caffe5bf 100644 --- a/src/fintamath/numbers/Integer.cpp +++ b/src/fintamath/numbers/Integer.cpp @@ -79,6 +79,11 @@ Integer &Integer::divide(const Integer &rhs) { return *this; } +Integer &Integer::negate() { + backend = -backend; + return *this; +} + Integer &Integer::mod(const Integer &rhs) { if (rhs == 0) { throw UndefinedBinaryOperatorException("mod", toString(), rhs.toString()); @@ -128,11 +133,6 @@ Integer &Integer::bitNot() { return *this; } -Integer &Integer::negate() { - backend = -backend; - return *this; -} - Integer &Integer::increase() { ++backend; return *this; @@ -143,4 +143,77 @@ Integer &Integer::decrease() { return *this; } +Integer &Integer::operator%=(const Integer &rhs) { + return mod(rhs); +} + +Integer &Integer::operator&=(const Integer &rhs) { + return bitAnd(rhs); +} + +Integer &Integer::operator|=(const Integer &rhs) { + return bitOr(rhs); +} + +Integer &Integer::operator^=(const Integer &rhs) { + return bitXor(rhs); +} + +Integer &Integer::operator<<=(const Integer &rhs) { + return bitLeftShift(rhs); +} + +Integer &Integer::operator>>=(const Integer &rhs) { + return bitRightShift(rhs); +} + +Integer Integer::operator%(const Integer &rhs) const { + return Integer(*this) %= rhs; +} + +Integer Integer::operator&(const Integer &rhs) const { + return Integer(*this) &= rhs; +} + +Integer Integer::operator|(const Integer &rhs) const { + return Integer(*this) |= rhs; +} + +Integer Integer::operator^(const Integer &rhs) const { + return Integer(*this) ^= rhs; +} + +Integer Integer::operator<<(const Integer &rhs) const { + return Integer(*this) <<= rhs; +} + +Integer Integer::operator>>(const Integer &rhs) const { + return Integer(*this) >>= rhs; +} + +Integer Integer::operator~() const { + Integer tmp = Integer(*this); + return tmp.bitNot(); +} + +Integer &Integer::operator++() { + return increase(); +} + +Integer &Integer::operator--() { + return decrease(); +} + +Integer Integer::operator++(int) { + Integer res = *this; + increase(); + return res; +} + +Integer Integer::operator--(int) { + Integer res = *this; + decrease(); + return res; +} + } diff --git a/src/fintamath/numbers/NumberAbstract.cpp b/src/fintamath/numbers/NumberAbstract.cpp index 9ad847284..bb48f1413 100644 --- a/src/fintamath/numbers/NumberAbstract.cpp +++ b/src/fintamath/numbers/NumberAbstract.cpp @@ -7,7 +7,6 @@ #include "fintamath/core/IComparable.hpp" #include "fintamath/core/IMathObject.hpp" #include "fintamath/core/MathObjectUtils.hpp" -#include "fintamath/numbers/IInteger.hpp" #include "fintamath/numbers/Integer.hpp" #include "fintamath/numbers/Rational.hpp" #include "fintamath/numbers/Real.hpp" @@ -19,7 +18,7 @@ std::unique_ptr Integer::multiplyAbstract(const IArithmetic &rhs) c return cast(Integer(0).clone()); } - return IIntegerCRTP::multiplyAbstract(rhs); + return INumberCRTP::multiplyAbstract(rhs); } std::unique_ptr Integer::divideAbstract(const IArithmetic &rhs) const { @@ -33,7 +32,7 @@ std::unique_ptr Integer::divideAbstract(const IArithmetic &rhs) con } } - return IIntegerCRTP::divideAbstract(rhs); + return INumberCRTP::divideAbstract(rhs); } //-------------------------------------------------------------------------------------// diff --git a/tests/src/numbers/IIntegerTests.cpp b/tests/src/numbers/IIntegerTests.cpp deleted file mode 100644 index e3ebacfcf..000000000 --- a/tests/src/numbers/IIntegerTests.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#include - -#include "fintamath/numbers/IInteger.hpp" - -#include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/numbers/Integer.hpp" - -using namespace fintamath; -using namespace detail; - -namespace { - -class TestInteger : public IIntegerCRTP { - FINTAMATH_PARENT_CLASS_BODY(TestInteger) - -protected: - TestInteger &mod(const TestInteger & /* rhs */) override { - return *this; - } - - TestInteger &bitAnd(const TestInteger &rhs) override { - return *this; - } - - TestInteger &bitOr(const TestInteger &rhs) override { - return *this; - } - - TestInteger &bitXor(const TestInteger &rhs) override { - return *this; - } - - TestInteger &bitLeftShift(const TestInteger &rhs) override { - return *this; - } - - TestInteger &bitRightShift(const TestInteger &rhs) override { - return *this; - } - - TestInteger &bitNot() override { - return *this; - } - - TestInteger &add(const TestInteger &rhs) override { - return *this; - } - - TestInteger &substract(const TestInteger &rhs) override { - return *this; - } - - TestInteger &multiply(const TestInteger &rhs) override { - return *this; - } - - TestInteger ÷(const TestInteger &rhs) override { - return *this; - } - - TestInteger &negate() override { - return *this; - } - - std::strong_ordering compare(const TestInteger &rhs) const override { - return std::strong_ordering::less; - } - - TestInteger &increase() override { - return *this; - } - - TestInteger &decrease() override { - return *this; - } -}; - -FINTAMATH_PARENT_CLASS_IMPLEMENTATION(TestInteger) - -class TestIntegerConvertible final : public TestInteger { - FINTAMATH_CLASS_BODY(TestIntegerConvertible) - -public: - TestIntegerConvertible() : TestInteger() { - } - - TestIntegerConvertible(const Integer &) : TestIntegerConvertible() { - } - - MathObjectClass getClass() const override { - return getClassStatic(); - } -}; - -[[maybe_unused]] const auto config = [] { - IInteger::registerType(); - TestInteger::registerType(); - - Converter::add( - [](const TestIntegerConvertible & /*type*/, const TestIntegerConvertible &value) { - return std::make_unique(value); - }); - Converter::add( - [](const TestIntegerConvertible & /*type*/, const Integer &value) { - return std::make_unique(value); - }); - - return 0; -}(); - -} - -TEST(IIntegerTests, parseTest) { - EXPECT_TRUE(is(*IInteger::parseFirst("TestInteger"))); -} - -TEST(IIntegerTests, modTest) { - std::unique_ptr m1 = std::make_unique(10); - std::unique_ptr m2 = std::make_unique(3); - - EXPECT_EQ((*m1 % *m1)->toString(), "0"); - EXPECT_EQ((*m2 % *m2)->toString(), "0"); - EXPECT_EQ((*m1 % *m2)->toString(), "1"); - EXPECT_EQ((*m2 % *m1)->toString(), "3"); - - EXPECT_TRUE(is(*m1 % *m1)); - EXPECT_TRUE(is(*m2 % *m2)); - EXPECT_TRUE(is(*m1 % *m2)); - EXPECT_TRUE(is(*m2 % *m1)); - - EXPECT_TRUE(is(*m1 % TestIntegerConvertible())); - EXPECT_TRUE(is(TestIntegerConvertible() % *m1)); - - EXPECT_THROW(*m1 % TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() % *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a %= 3).toString(), "0"); -} - -TEST(IIntegerTests, bitAndTest) { - std::unique_ptr m1 = std::make_unique(10); - std::unique_ptr m2 = std::make_unique(3); - - EXPECT_EQ((*m1 & *m1)->toString(), "10"); - EXPECT_EQ((*m2 & *m2)->toString(), "3"); - EXPECT_EQ((*m1 & *m2)->toString(), "2"); - EXPECT_EQ((*m2 & *m1)->toString(), "2"); - - EXPECT_TRUE(is(*m1 & *m1)); - EXPECT_TRUE(is(*m2 & *m2)); - EXPECT_TRUE(is(*m1 & *m2)); - EXPECT_TRUE(is(*m2 & *m1)); - - EXPECT_TRUE(is(*m1 & TestIntegerConvertible())); - EXPECT_TRUE(is(TestIntegerConvertible() & *m1)); - - EXPECT_THROW(*m1 & TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() & *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a &= 3).toString(), "0"); -} - -TEST(IIntegerTests, bitOrTest) { - std::unique_ptr m1 = std::make_unique(10); - std::unique_ptr m2 = std::make_unique(3); - - EXPECT_EQ((*m1 | *m1)->toString(), "10"); - EXPECT_EQ((*m2 | *m2)->toString(), "3"); - EXPECT_EQ((*m1 | *m2)->toString(), "11"); - EXPECT_EQ((*m2 | *m1)->toString(), "11"); - - EXPECT_TRUE(is(*m1 | *m1)); - EXPECT_TRUE(is(*m2 | *m2)); - EXPECT_TRUE(is(*m1 | *m2)); - EXPECT_TRUE(is(*m2 | *m1)); - - EXPECT_TRUE(is(*m1 | TestIntegerConvertible())); - EXPECT_TRUE(is(TestIntegerConvertible() | *m1)); - - EXPECT_THROW(*m1 | TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() | *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a |= 3).toString(), "3"); -} - -TEST(IIntegerTests, bitXorTest) { - std::unique_ptr m1 = std::make_unique(10); - std::unique_ptr m2 = std::make_unique(3); - - EXPECT_EQ((*m1 ^ *m1)->toString(), "0"); - EXPECT_EQ((*m2 ^ *m2)->toString(), "0"); - EXPECT_EQ((*m1 ^ *m2)->toString(), "9"); - EXPECT_EQ((*m2 ^ *m1)->toString(), "9"); - - EXPECT_TRUE(is(*m1 ^ *m1)); - EXPECT_TRUE(is(*m2 ^ *m2)); - EXPECT_TRUE(is(*m1 ^ *m2)); - EXPECT_TRUE(is(*m2 ^ *m1)); - - EXPECT_TRUE(is(*m1 ^ TestIntegerConvertible())); - EXPECT_TRUE(is(TestIntegerConvertible() ^ *m1)); - - EXPECT_THROW(*m1 ^ TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() ^ *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a ^= 3).toString(), "3"); -} - -TEST(IIntegerTests, bitLeftShiftTest) { - std::unique_ptr m1 = std::make_unique(10); - std::unique_ptr m2 = std::make_unique(3); - - EXPECT_EQ((*m1 << *m1)->toString(), "10240"); - EXPECT_EQ((*m2 << *m2)->toString(), "24"); - EXPECT_EQ((*m1 << *m2)->toString(), "80"); - EXPECT_EQ((*m2 << *m1)->toString(), "3072"); - - EXPECT_TRUE(is(*m1 << *m1)); - EXPECT_TRUE(is(*m2 << *m2)); - EXPECT_TRUE(is(*m1 << *m2)); - EXPECT_TRUE(is(*m2 << *m1)); - - EXPECT_TRUE(is(*m1 << TestIntegerConvertible())); - EXPECT_TRUE(is(TestIntegerConvertible() << *m1)); - - EXPECT_THROW(*m1 << TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() << *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a <<= 3).toString(), "0"); -} - -TEST(IIntegerTests, bitRightShiftTest) { - std::unique_ptr m1 = std::make_unique(10); - std::unique_ptr m2 = std::make_unique(3); - - EXPECT_EQ((*m1 >> *m1)->toString(), "0"); - EXPECT_EQ((*m2 >> *m2)->toString(), "0"); - EXPECT_EQ((*m1 >> *m2)->toString(), "1"); - EXPECT_EQ((*m2 >> *m1)->toString(), "0"); - - EXPECT_TRUE(is(*m1 >> *m1)); - EXPECT_TRUE(is(*m2 >> *m2)); - EXPECT_TRUE(is(*m1 >> *m2)); - EXPECT_TRUE(is(*m2 >> *m1)); - - EXPECT_TRUE(is(*m1 >> TestIntegerConvertible())); - EXPECT_TRUE(is(TestIntegerConvertible() >> *m1)); - - EXPECT_THROW(*m1 >> TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() >> *m1, InvalidInputBinaryOperatorException); - - Integer a; - EXPECT_EQ((a >>= 3).toString(), "0"); -} - -TEST(IIntegerTests, bitNotTest) { - const std::unique_ptr m1 = std::make_unique(44); - EXPECT_EQ((~*m1)->toString(), "-45"); - - EXPECT_EQ((~Integer(1)).toString(), "-2"); -} - -TEST(IIntegerTests, incTest) { - const std::unique_ptr m1 = std::make_unique(1); - EXPECT_EQ((++*m1).toString(), "2"); - EXPECT_EQ(((*m1)++)->toString(), "2"); - EXPECT_EQ(m1->toString(), "3"); - - EXPECT_EQ((++Integer(1)).toString(), "2"); - EXPECT_EQ((Integer(1)++).toString(), "1"); -} - -TEST(IIntegerTests, decTest) { - const std::unique_ptr m1 = std::make_unique(1); - EXPECT_EQ((--*m1).toString(), "0"); - EXPECT_EQ(((*m1)--)->toString(), "0"); - EXPECT_EQ(m1->toString(), "-1"); - - EXPECT_EQ((--Integer(1)).toString(), "0"); - EXPECT_EQ((Integer(1)--).toString(), "1"); -} - -TEST(IIntegerTests, getClassTest) { - EXPECT_EQ(IInteger::getClassStatic(), MathObjectClass("IInteger")); - EXPECT_EQ(IInteger::getClassStatic().getParent(), INumber::getClassStatic()); -} diff --git a/tests/src/numbers/IntegerTests.cpp b/tests/src/numbers/IntegerTests.cpp index 6bbf95218..e1dc2d504 100644 --- a/tests/src/numbers/IntegerTests.cpp +++ b/tests/src/numbers/IntegerTests.cpp @@ -610,7 +610,7 @@ TEST(IntegerTests, equalsTest) { TEST(IntegerTests, getClassTest) { EXPECT_EQ(Integer().getClass(), MathObjectClass("Integer")); - EXPECT_EQ(Integer().getClass().getParent(), IInteger::getClassStatic()); + EXPECT_EQ(Integer().getClass().getParent(), INumber::getClassStatic()); } TEST(IntegerTests, hashTest) { From 032cf115a5622b43c56a9201bf1d21674a4467a3 Mon Sep 17 00:00:00 2001 From: fintarin Date: Fri, 5 Apr 2024 22:47:38 +0400 Subject: [PATCH 2/3] Use noexcept if function doesn't throw any exception --- include/fintamath/core/Converter.hpp | 6 ++--- include/fintamath/core/IMathObject.hpp | 20 +++++++------- include/fintamath/core/IMathObjectCRTP.hpp | 16 ++++++------ include/fintamath/core/MathObjectBody.hpp | 26 +++++++++---------- include/fintamath/core/MathObjectClass.hpp | 26 +++++++++---------- include/fintamath/core/MathObjectUtils.hpp | 24 ++++++++--------- include/fintamath/core/MultiMethod.hpp | 14 +++++----- include/fintamath/core/Parser.hpp | 8 +++--- include/fintamath/core/Tokenizer.hpp | 4 +-- .../exceptions/InvalidInputException.hpp | 10 +++---- .../exceptions/UndefinedException.hpp | 10 +++---- include/fintamath/expressions/Expression.hpp | 6 ++--- include/fintamath/expressions/IExpression.hpp | 8 +++--- .../fintamath/expressions/IExpressionCRTP.hpp | 2 +- .../interfaces/IBinaryExpression.hpp | 6 ++--- .../interfaces/IPolynomExpression.hpp | 6 ++--- .../interfaces/IUnaryExpression.hpp | 6 ++--- .../fintamath/functions/arithmetic/Abs.hpp | 2 +- .../fintamath/functions/arithmetic/Add.hpp | 2 +- .../fintamath/functions/arithmetic/Div.hpp | 2 +- .../fintamath/functions/arithmetic/Frac.hpp | 2 +- .../functions/arithmetic/FracMixed.hpp | 2 +- .../fintamath/functions/arithmetic/Mul.hpp | 2 +- .../fintamath/functions/arithmetic/Neg.hpp | 2 +- .../fintamath/functions/arithmetic/Sign.hpp | 2 +- .../fintamath/functions/arithmetic/Sub.hpp | 2 +- .../functions/arithmetic/UnaryPlus.hpp | 2 +- .../functions/calculus/Derivative.hpp | 2 +- .../fintamath/functions/calculus/Integral.hpp | 2 +- include/fintamath/functions/calculus/Max.hpp | 2 +- include/fintamath/functions/calculus/Min.hpp | 2 +- .../fintamath/functions/comparison/Eqv.hpp | 2 +- .../fintamath/functions/comparison/Less.hpp | 2 +- .../functions/comparison/LessEqv.hpp | 2 +- .../fintamath/functions/comparison/More.hpp | 2 +- .../functions/comparison/MoreEqv.hpp | 2 +- .../fintamath/functions/comparison/Neqv.hpp | 2 +- .../fintamath/functions/hyperbolic/Acosh.hpp | 2 +- .../fintamath/functions/hyperbolic/Acoth.hpp | 2 +- .../fintamath/functions/hyperbolic/Acsch.hpp | 2 +- .../fintamath/functions/hyperbolic/Asech.hpp | 2 +- .../fintamath/functions/hyperbolic/Asinh.hpp | 2 +- .../fintamath/functions/hyperbolic/Atanh.hpp | 2 +- .../fintamath/functions/hyperbolic/Cosh.hpp | 2 +- .../fintamath/functions/hyperbolic/Coth.hpp | 2 +- .../fintamath/functions/hyperbolic/Csch.hpp | 2 +- .../fintamath/functions/hyperbolic/Sech.hpp | 2 +- .../fintamath/functions/hyperbolic/Sinh.hpp | 2 +- .../fintamath/functions/hyperbolic/Tanh.hpp | 2 +- include/fintamath/functions/logarithms/Lb.hpp | 2 +- include/fintamath/functions/logarithms/Lg.hpp | 2 +- include/fintamath/functions/logarithms/Ln.hpp | 2 +- .../fintamath/functions/logarithms/Log.hpp | 2 +- include/fintamath/functions/logic/And.hpp | 2 +- include/fintamath/functions/logic/Equiv.hpp | 2 +- include/fintamath/functions/logic/Impl.hpp | 2 +- include/fintamath/functions/logic/Nequiv.hpp | 2 +- include/fintamath/functions/logic/Not.hpp | 2 +- include/fintamath/functions/logic/Or.hpp | 2 +- include/fintamath/functions/ntheory/Ceil.hpp | 2 +- include/fintamath/functions/ntheory/Floor.hpp | 2 +- include/fintamath/functions/ntheory/Mod.hpp | 2 +- include/fintamath/functions/other/Comma.hpp | 2 +- include/fintamath/functions/other/Deg.hpp | 2 +- .../fintamath/functions/other/Factorial.hpp | 2 +- include/fintamath/functions/other/Index.hpp | 2 +- include/fintamath/functions/other/Percent.hpp | 2 +- include/fintamath/functions/powers/Exp.hpp | 2 +- include/fintamath/functions/powers/Pow.hpp | 2 +- .../functions/powers/PowFunction.hpp | 2 +- include/fintamath/functions/powers/Root.hpp | 2 +- include/fintamath/functions/powers/Sqr.hpp | 2 +- include/fintamath/functions/powers/Sqrt.hpp | 2 +- .../fintamath/functions/trigonometry/Acos.hpp | 2 +- .../fintamath/functions/trigonometry/Acot.hpp | 2 +- .../fintamath/functions/trigonometry/Acsc.hpp | 2 +- .../fintamath/functions/trigonometry/Asec.hpp | 2 +- .../fintamath/functions/trigonometry/Asin.hpp | 2 +- .../fintamath/functions/trigonometry/Atan.hpp | 2 +- .../fintamath/functions/trigonometry/Cos.hpp | 2 +- .../fintamath/functions/trigonometry/Cot.hpp | 2 +- .../fintamath/functions/trigonometry/Csc.hpp | 2 +- .../fintamath/functions/trigonometry/Sec.hpp | 2 +- .../fintamath/functions/trigonometry/Sin.hpp | 2 +- .../fintamath/functions/trigonometry/Tan.hpp | 2 +- include/fintamath/literals/Boolean.hpp | 2 +- include/fintamath/literals/Variable.hpp | 2 +- .../literals/constants/ComplexInf.hpp | 2 +- include/fintamath/literals/constants/E.hpp | 2 +- .../fintamath/literals/constants/False.hpp | 2 +- include/fintamath/literals/constants/I.hpp | 2 +- include/fintamath/literals/constants/Inf.hpp | 2 +- .../fintamath/literals/constants/NegInf.hpp | 2 +- include/fintamath/literals/constants/Pi.hpp | 2 +- include/fintamath/literals/constants/True.hpp | 2 +- .../literals/constants/Undefined.hpp | 2 +- include/fintamath/numbers/Complex.hpp | 6 ++--- include/fintamath/numbers/Integer.hpp | 4 +-- include/fintamath/numbers/Rational.hpp | 6 ++--- include/fintamath/numbers/Real.hpp | 10 +++---- src/fintamath/core/MathObjectClass.cpp | 16 ++++++------ src/fintamath/core/Tokenizer.cpp | 4 +-- src/fintamath/expressions/Expression.cpp | 6 ++--- .../expressions/FunctionExpression.cpp | 6 ++--- .../expressions/FunctionExpression.hpp | 6 ++--- src/fintamath/expressions/IExpression.cpp | 4 +-- src/fintamath/expressions/binary/CompExpr.cpp | 2 +- src/fintamath/expressions/binary/CompExpr.hpp | 2 +- src/fintamath/expressions/binary/DivExpr.cpp | 2 +- src/fintamath/expressions/binary/DivExpr.hpp | 2 +- src/fintamath/expressions/binary/LogExpr.cpp | 4 +-- src/fintamath/expressions/binary/LogExpr.hpp | 4 +-- src/fintamath/expressions/binary/PowExpr.cpp | 8 +++--- src/fintamath/expressions/binary/PowExpr.hpp | 4 +-- .../interfaces/IBinaryExpression.cpp | 6 ++--- .../interfaces/IPolynomExpression.cpp | 6 ++--- .../interfaces/IUnaryExpression.cpp | 6 ++--- .../expressions/polynomial/MulExpr.cpp | 2 +- .../expressions/polynomial/MulExpr.hpp | 2 +- src/fintamath/literals/Boolean.cpp | 2 +- src/fintamath/literals/Variable.cpp | 2 +- src/fintamath/numbers/Complex.cpp | 6 ++--- src/fintamath/numbers/Integer.cpp | 4 +-- src/fintamath/numbers/NumberAbstract.cpp | 2 +- src/fintamath/numbers/Rational.cpp | 6 ++--- src/fintamath/numbers/Real.cpp | 18 ++++--------- .../expressions/FunctionExpressionTests.cpp | 10 +++---- tests/src/expressions/IExpressionTests.cpp | 4 +-- .../functions/calculus/DerivativeTests.cpp | 2 +- tests/src/numbers/RealTests.cpp | 7 ----- 130 files changed, 260 insertions(+), 277 deletions(-) diff --git a/include/fintamath/core/Converter.hpp b/include/fintamath/core/Converter.hpp index 370ad0778..471ff05c1 100644 --- a/include/fintamath/core/Converter.hpp +++ b/include/fintamath/core/Converter.hpp @@ -19,16 +19,16 @@ class Converter final { using ConverterMultiMethod = MultiMethod(const IMathObject &, const IMathObject &)>; public: - static std::unique_ptr convert(const IMathObject &to, const IMathObject &from) { + static std::unique_ptr convert(const IMathObject &to, const IMathObject &from) noexcept { return getConverter()(to, from); } - static bool isConvertible(const IMathObject &to, const IMathObject &from) { + static bool isConvertible(const IMathObject &to, const IMathObject &from) noexcept { return getConverter().contains(to, from); } template To, std::derived_from From> - static void add(const ConverterFunction &convertFunc) { + static void add(const ConverterFunction &convertFunc) noexcept { getConverter().add(convertFunc); } diff --git a/include/fintamath/core/IMathObject.hpp b/include/fintamath/core/IMathObject.hpp index 1d225c889..903b22539 100644 --- a/include/fintamath/core/IMathObject.hpp +++ b/include/fintamath/core/IMathObject.hpp @@ -18,28 +18,28 @@ class IMathObject { FINTAMATH_PARENT_CLASS_BODY(IMathObject) public: - virtual ~IMathObject() = default; + virtual ~IMathObject() noexcept = default; - virtual std::unique_ptr clone() const & = 0; + virtual std::unique_ptr clone() const & noexcept = 0; - virtual std::unique_ptr clone() && = 0; + virtual std::unique_ptr clone() && noexcept = 0; - virtual std::string toString() const { + virtual std::string toString() const noexcept { return std::string(getClass().getName()); } - virtual std::unique_ptr toMinimalObject() const { + virtual std::unique_ptr toMinimalObject() const noexcept { return clone(); } - virtual MathObjectClass getClass() const = 0; + virtual MathObjectClass getClass() const noexcept = 0; - friend bool operator==(const IMathObject &lhs, const IMathObject &rhs) { + friend bool operator==(const IMathObject &lhs, const IMathObject &rhs) noexcept { return lhs.equalsAbstract(rhs); } protected: - virtual bool equalsAbstract(const IMathObject &rhs) const = 0; + virtual bool equalsAbstract(const IMathObject &rhs) const noexcept = 0; }; template @@ -50,11 +50,11 @@ class IMathObjectCRTP : public IMathObject { }; template Lhs, ConvertibleToAndNotSameAs Rhs> -bool operator==(const Lhs &lhs, const Rhs &rhs) { +bool operator==(const Lhs &lhs, const Rhs &rhs) noexcept { return lhs == Lhs(rhs); } -inline std::ostream &operator<<(std::ostream &out, const IMathObject &rhs) { +inline std::ostream &operator<<(std::ostream &out, const IMathObject &rhs) noexcept { return out << rhs.toString(); } diff --git a/include/fintamath/core/IMathObjectCRTP.hpp b/include/fintamath/core/IMathObjectCRTP.hpp index e7b386f83..d8250cbc7 100644 --- a/include/fintamath/core/IMathObjectCRTP.hpp +++ b/include/fintamath/core/IMathObjectCRTP.hpp @@ -10,28 +10,28 @@ class IMathObjectCRTP_ : public IMathObject { #endif // I_MATH_OBJECT_CRTP public: - std::unique_ptr clone() const & final { + std::unique_ptr clone() const & noexcept final { return std::make_unique(cast(*this)); } - std::unique_ptr clone() && final { + std::unique_ptr clone() && noexcept final { return std::make_unique(std::move(cast(*this))); } - bool operator==(const I_MATH_OBJECT_CRTP &rhs) const { - return equals(cast(rhs)); + MathObjectClass getClass() const noexcept final { + return Derived::getClassStatic(); } - MathObjectClass getClass() const override { - return Derived::getClassStatic(); + bool operator==(const I_MATH_OBJECT_CRTP &rhs) const noexcept { + return equals(cast(rhs)); } protected: - virtual bool equals(const Derived &rhs) const { + virtual bool equals(const Derived &rhs) const noexcept { return toString() == rhs.toString(); } - bool equalsAbstract(const IMathObject &rhs) const override { + bool equalsAbstract(const IMathObject &rhs) const noexcept override { if (const auto *rhsPtr = cast(&rhs)) { return equals(*rhsPtr); } diff --git a/include/fintamath/core/MathObjectBody.hpp b/include/fintamath/core/MathObjectBody.hpp index 8918b4b83..20cbdad97 100644 --- a/include/fintamath/core/MathObjectBody.hpp +++ b/include/fintamath/core/MathObjectBody.hpp @@ -5,12 +5,12 @@ #include "fintamath/core/MathObjectClass.hpp" #include "fintamath/core/Parser.hpp" -#define FINTAMATH_CLASS_BODY(Class) \ -public: \ - static constexpr MathObjectClass getClassStatic() { \ - return {#Class}; \ - } \ - \ +#define FINTAMATH_CLASS_BODY(Class) \ +public: \ + static constexpr MathObjectClass getClassStatic() noexcept { \ + return {#Class}; \ + } \ + \ private: #define FINTAMATH_PARENT_CLASS_BODY(Class) \ @@ -19,7 +19,7 @@ public: \ private: \ using Class##Parser = detail::Parser>; \ \ - static Class##Parser &getParser(); \ + static Class##Parser &getParser() noexcept; \ \ public: \ static auto parse(std::string str) { \ @@ -31,15 +31,15 @@ public: \ } \ \ template T> \ - static void registerType() { \ + static void registerType() noexcept { \ MathObjectClass::bindTypes(); \ - getParser().registerType(); \ + getParser().template registerType(); \ } \ \ private: -#define FINTAMATH_PARENT_CLASS_IMPLEMENTATION(Class) \ - Class::Class##Parser &Class::getParser() { \ - static Class##Parser parser; \ - return parser; \ +#define FINTAMATH_PARENT_CLASS_IMPLEMENTATION(Class) \ + Class::Class##Parser &Class::getParser() noexcept { \ + static Class##Parser parser; \ + return parser; \ } diff --git a/include/fintamath/core/MathObjectClass.hpp b/include/fintamath/core/MathObjectClass.hpp index cbbb233c3..f3d2d0391 100644 --- a/include/fintamath/core/MathObjectClass.hpp +++ b/include/fintamath/core/MathObjectClass.hpp @@ -38,36 +38,36 @@ class MathObjectClass final { using ParentToChildrenMap = std::unordered_map; public: - constexpr MathObjectClass(const Name inName) : name(inName) { + constexpr MathObjectClass(const Name inName) noexcept : name(inName) { } - constexpr Name getName() const { + constexpr Name getName() const noexcept { return name; } - constexpr bool operator==(const MathObjectClass rhs) const { + constexpr bool operator==(const MathObjectClass rhs) const noexcept { return name == rhs.name; } - std::strong_ordering operator<=>(MathObjectClass rhs) const; + std::strong_ordering operator<=>(MathObjectClass rhs) const noexcept; - std::optional getParent() const; + std::optional getParent() const noexcept; - const Children &getChildren(bool recursive = false) const; + const Children &getChildren(bool recursive = false) const noexcept; template Child> - static void bindTypes(); + static void bindTypes() noexcept; private: - Id getId() const; + Id getId() const noexcept; - static ClassToIdMap &getClassToIdMap(); + static ClassToIdMap &getClassToIdMap() noexcept; - static ChildToParentMap &getChildToParentMap(); + static ChildToParentMap &getChildToParentMap() noexcept; - static ParentToChildrenMap &getParentToChildrenMap(); + static ParentToChildrenMap &getParentToChildrenMap() noexcept; - static ParentToChildrenMap &getParentToRecursiveChildrenMap(); + static ParentToChildrenMap &getParentToRecursiveChildrenMap() noexcept; private: Name name; @@ -78,7 +78,7 @@ class MathObjectClass final { }; template Child> -void MathObjectClass::bindTypes() { +void MathObjectClass::bindTypes() noexcept { MathObjectClass parent = Parent::getClassStatic(); MathObjectClass child = Child::getClassStatic(); diff --git a/include/fintamath/core/MathObjectUtils.hpp b/include/fintamath/core/MathObjectUtils.hpp index 2fcd49c96..50e8a2ee5 100644 --- a/include/fintamath/core/MathObjectUtils.hpp +++ b/include/fintamath/core/MathObjectUtils.hpp @@ -11,12 +11,12 @@ namespace fintamath { class IMathObject; -inline bool is(const MathObjectClass to, const MathObjectClass from) { +inline bool is(const MathObjectClass to, const MathObjectClass from) noexcept { return to == from || to.getChildren(true).contains(from); } template To, std::derived_from From> -bool is(const From &from) { +bool is(const From &from) noexcept { if constexpr (std::is_base_of_v) { return true; } @@ -29,7 +29,7 @@ bool is(const From &from) { } template To, std::derived_from From> -bool is(const From *from) { +bool is(const From *from) noexcept { if (!from) { return false; } @@ -38,27 +38,27 @@ bool is(const From *from) { } template To, std::derived_from From> -bool is(const std::unique_ptr &from) { +bool is(const std::unique_ptr &from) noexcept { return is(from.get()); } template To, std::derived_from From> -bool is(const std::shared_ptr &from) { +bool is(const std::shared_ptr &from) noexcept { return is(from.get()); } template To, std::derived_from From> -bool is(const std::shared_ptr &from) { +bool is(const std::shared_ptr &from) noexcept { return is(from.get()); } template To, std::derived_from From> -bool is(const std::reference_wrapper &from) { +bool is(const std::reference_wrapper &from) noexcept { return is(from.get()); } template To, std::derived_from From> -bool is(const std::reference_wrapper &from) { +bool is(const std::reference_wrapper &from) noexcept { return is(from.get()); } @@ -85,7 +85,7 @@ To &cast(From &from) { } template To, std::derived_from From> -const To *cast(const From *from) { +const To *cast(const From *from) noexcept { if constexpr (!std::is_base_of_v) { if (!is(from)) { return {}; @@ -96,7 +96,7 @@ const To *cast(const From *from) { } template To, std::derived_from From> -To *cast(From *from) { +To *cast(From *from) noexcept { if constexpr (!std::is_base_of_v) { if (!is(from)) { return {}; @@ -107,7 +107,7 @@ To *cast(From *from) { } template To, std::derived_from From> -std::unique_ptr cast(std::unique_ptr &&from) { +std::unique_ptr cast(std::unique_ptr &&from) noexcept { if constexpr (!std::is_base_of_v) { if (!is(from)) { from.reset(); @@ -121,7 +121,7 @@ std::unique_ptr cast(std::unique_ptr &&from) { } template To, std::derived_from From> -std::shared_ptr cast(const std::shared_ptr &from) { +std::shared_ptr cast(const std::shared_ptr &from) noexcept { if constexpr (!std::is_base_of_v) { if (!is(from)) { return {}; diff --git a/include/fintamath/core/MultiMethod.hpp b/include/fintamath/core/MultiMethod.hpp index f067eaf77..5c8828acd 100644 --- a/include/fintamath/core/MultiMethod.hpp +++ b/include/fintamath/core/MultiMethod.hpp @@ -27,12 +27,18 @@ class MultiMethod final { public: template requires(sizeof...(Args) == sizeof...(ArgsBase)) - void add(const auto &func) { + void add(const auto &func) noexcept { idToCallbackMap[CallbackId(Args::getClassStatic()...)] = [func](const ArgsBase &...args) { return func(cast(args)...); }; } + template + requires(sizeof...(Args) == sizeof...(ArgsBase)) + bool contains(const Args &...args) const noexcept { + return idToCallbackMap.contains(CallbackId(args.getClass()...)); + } + template requires(sizeof...(Args) == sizeof...(ArgsBase)) Res operator()(Args &&...args) const { @@ -43,12 +49,6 @@ class MultiMethod final { return {}; } - template - requires(sizeof...(Args) == sizeof...(ArgsBase)) - bool contains(const Args &...args) const { - return idToCallbackMap.contains(CallbackId(args.getClass()...)); - } - private: IdToCallbackMap idToCallbackMap; }; diff --git a/include/fintamath/core/Parser.hpp b/include/fintamath/core/Parser.hpp index f1fc3d6e9..22f9acf58 100644 --- a/include/fintamath/core/Parser.hpp +++ b/include/fintamath/core/Parser.hpp @@ -69,7 +69,7 @@ class Parser final { template requires(!std::is_abstract_v && !StringConstructable && EmptyConstructable) - void registerType() { + void registerType() noexcept { static const std::string name = Type{}.toString(); stringToConstructorsMap[name].emplace_back([]() -> Return { @@ -81,7 +81,7 @@ class Parser final { template requires(!std::is_abstract_v && StringConstructable) - void registerType() { + void registerType() noexcept { generatorConstructors.emplace_back([](std::string str) -> Generator { try { co_yield std::make_unique(std::move(str)); @@ -94,7 +94,7 @@ class Parser final { template requires(std::is_abstract_v) - void registerType() { + void registerType() noexcept { generatorConstructors.emplace_back([](std::string str) -> Generator { for (auto &value : Type::parse(std::move(str))) { co_yield std::move(value); @@ -103,7 +103,7 @@ class Parser final { } template - void registerType() const { + void registerType() const noexcept { // No object of this type can be constructed } diff --git a/include/fintamath/core/Tokenizer.hpp b/include/fintamath/core/Tokenizer.hpp index f2f3dc44b..38f604e65 100644 --- a/include/fintamath/core/Tokenizer.hpp +++ b/include/fintamath/core/Tokenizer.hpp @@ -12,7 +12,7 @@ class Tokenizer final { public: static TokenVector tokenize(std::string str); - static void registerToken(const Token &token); + static void registerToken(const Token &token) noexcept; private: static bool appendToken(TokenVector &tokens, Token &token, bool shouldSplit = false); @@ -23,7 +23,7 @@ class Tokenizer final { static bool isSpace(char ch); - static TokenVector &getRegisteredTokens(); + static TokenVector &getRegisteredTokens() noexcept; }; } diff --git a/include/fintamath/exceptions/InvalidInputException.hpp b/include/fintamath/exceptions/InvalidInputException.hpp index de2f10aba..2fb93e578 100644 --- a/include/fintamath/exceptions/InvalidInputException.hpp +++ b/include/fintamath/exceptions/InvalidInputException.hpp @@ -10,9 +10,9 @@ namespace fintamath { class InvalidInputException : public Exception { public: - InvalidInputException() = default; + InvalidInputException() noexcept = default; - explicit InvalidInputException(const std::string &input) { + explicit InvalidInputException(const std::string &input) noexcept { content += ": " + input; } @@ -26,7 +26,7 @@ class InvalidInputException : public Exception { class InvalidInputFunctionException final : public InvalidInputException { public: - explicit InvalidInputFunctionException(const std::string &func, const std::vector &argVect) { + explicit InvalidInputFunctionException(const std::string &func, const std::vector &argVect) noexcept { content += ": " + func + "("; if (!argVect.empty()) { @@ -47,7 +47,7 @@ class InvalidInputFunctionException final : public InvalidInputException { class InvalidInputBinaryOperatorException final : public InvalidInputException { public: - explicit InvalidInputBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) { + explicit InvalidInputBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) noexcept { content += ": (" + lhs + ")" + oper + "(" + rhs + ")"; } }; @@ -60,7 +60,7 @@ class InvalidInputUnaryOperatorException final : public InvalidInputException { }; public: - explicit InvalidInputUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) { + explicit InvalidInputUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) noexcept { switch (type) { case Type::Prefix: content += ": " + oper + "(" + rhs + ")"; diff --git a/include/fintamath/exceptions/UndefinedException.hpp b/include/fintamath/exceptions/UndefinedException.hpp index 56ab666db..213fb16ea 100644 --- a/include/fintamath/exceptions/UndefinedException.hpp +++ b/include/fintamath/exceptions/UndefinedException.hpp @@ -10,9 +10,9 @@ namespace fintamath { class UndefinedException : public Exception { public: - UndefinedException() = default; + UndefinedException() noexcept = default; - explicit UndefinedException(const std::string &input) { + explicit UndefinedException(const std::string &input) noexcept { content += ": " + input; } @@ -26,7 +26,7 @@ class UndefinedException : public Exception { class UndefinedFunctionException final : public UndefinedException { public: - explicit UndefinedFunctionException(const std::string &func, const std::vector &argVect) { + explicit UndefinedFunctionException(const std::string &func, const std::vector &argVect) noexcept { content += ": " + func + "("; if (!argVect.empty()) { @@ -47,7 +47,7 @@ class UndefinedFunctionException final : public UndefinedException { class UndefinedBinaryOperatorException final : public UndefinedException { public: - explicit UndefinedBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) { + explicit UndefinedBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) noexcept { content += ": (" + lhs + ")" + oper + "(" + rhs + ")"; } }; @@ -60,7 +60,7 @@ class UndefinedUnaryOperatorException final : public UndefinedException { }; public: - explicit UndefinedUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) { + explicit UndefinedUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) noexcept { switch (type) { case Type::Prefix: content += ": " + oper + "(" + rhs + ")"; diff --git a/include/fintamath/expressions/Expression.hpp b/include/fintamath/expressions/Expression.hpp index c8e4de64f..706a7beaa 100644 --- a/include/fintamath/expressions/Expression.hpp +++ b/include/fintamath/expressions/Expression.hpp @@ -78,11 +78,11 @@ class Expression final : public IExpressionCRTP { Expression(int64_t val); - std::string toString() const override; + std::string toString() const noexcept override; - const std::shared_ptr &getFunction() const override; + const std::shared_ptr &getFunction() const noexcept override; - const ArgumentPtrVector &getChildren() const override; + const ArgumentPtrVector &getChildren() const noexcept override; void setChildren(const ArgumentPtrVector &childVect) override; diff --git a/include/fintamath/expressions/IExpression.hpp b/include/fintamath/expressions/IExpression.hpp index 21f47b3be..7a02b3e1c 100644 --- a/include/fintamath/expressions/IExpression.hpp +++ b/include/fintamath/expressions/IExpression.hpp @@ -21,9 +21,9 @@ class IExpression : public IMathObject { FINTAMATH_PARENT_CLASS_BODY(IExpression) public: - virtual const std::shared_ptr &getFunction() const = 0; + virtual const std::shared_ptr &getFunction() const noexcept = 0; - virtual const ArgumentPtrVector &getChildren() const = 0; + virtual const ArgumentPtrVector &getChildren() const noexcept = 0; virtual void setChildren(const ArgumentPtrVector &childVect) = 0; @@ -31,9 +31,9 @@ class IExpression : public IMathObject { virtual void setVariables(const std::vector> &varsToVals); - std::unique_ptr toMinimalObject() const final; + std::unique_ptr toMinimalObject() const noexcept final; - virtual const std::shared_ptr &getOutputFunction() const; + virtual const std::shared_ptr &getOutputFunction() const noexcept; protected: virtual ArgumentPtr simplify() const; diff --git a/include/fintamath/expressions/IExpressionCRTP.hpp b/include/fintamath/expressions/IExpressionCRTP.hpp index 2ccde94db..b6e7d197c 100644 --- a/include/fintamath/expressions/IExpressionCRTP.hpp +++ b/include/fintamath/expressions/IExpressionCRTP.hpp @@ -10,7 +10,7 @@ class IExpressionCRTP_ : public IExpressionBaseCRTP { #endif // I_EXPRESSION_CRTP public: - bool equals(const Derived &rhs) const override { + bool equals(const Derived &rhs) const noexcept override { if (static_cast(this->getFunction()) != static_cast(rhs.getFunction()) || (this->getFunction() && rhs.getFunction() && *this->getFunction() != *rhs.getFunction())) { diff --git a/include/fintamath/expressions/interfaces/IBinaryExpression.hpp b/include/fintamath/expressions/interfaces/IBinaryExpression.hpp index 7d65d6dc6..08e38f2f8 100644 --- a/include/fintamath/expressions/interfaces/IBinaryExpression.hpp +++ b/include/fintamath/expressions/interfaces/IBinaryExpression.hpp @@ -19,11 +19,11 @@ class IBinaryExpression : public IExpression { public: explicit IBinaryExpression(const IFunction &inFunc, ArgumentPtr lhs, ArgumentPtr rhs); - std::string toString() const override; + std::string toString() const noexcept override; - const std::shared_ptr &getFunction() const final; + const std::shared_ptr &getFunction() const noexcept final; - const ArgumentPtrVector &getChildren() const final; + const ArgumentPtrVector &getChildren() const noexcept final; void setChildren(const ArgumentPtrVector &childVect) final; diff --git a/include/fintamath/expressions/interfaces/IPolynomExpression.hpp b/include/fintamath/expressions/interfaces/IPolynomExpression.hpp index daaf0739f..34857c190 100644 --- a/include/fintamath/expressions/interfaces/IPolynomExpression.hpp +++ b/include/fintamath/expressions/interfaces/IPolynomExpression.hpp @@ -22,11 +22,11 @@ class IPolynomExpression : public IExpression { public: explicit IPolynomExpression(const IFunction &inFunc, ArgumentPtrVector args); - std::string toString() const override; + std::string toString() const noexcept override; - const std::shared_ptr &getFunction() const final; + const std::shared_ptr &getFunction() const noexcept final; - const ArgumentPtrVector &getChildren() const final; + const ArgumentPtrVector &getChildren() const noexcept final; void setChildren(const ArgumentPtrVector &childVect) final; diff --git a/include/fintamath/expressions/interfaces/IUnaryExpression.hpp b/include/fintamath/expressions/interfaces/IUnaryExpression.hpp index fab8029a7..e5decb2d5 100644 --- a/include/fintamath/expressions/interfaces/IUnaryExpression.hpp +++ b/include/fintamath/expressions/interfaces/IUnaryExpression.hpp @@ -19,11 +19,11 @@ class IUnaryExpression : public IExpression { public: explicit IUnaryExpression(const IFunction &inFunc, ArgumentPtr rhs); - std::string toString() const override; + std::string toString() const noexcept override; - const std::shared_ptr &getFunction() const final; + const std::shared_ptr &getFunction() const noexcept final; - const ArgumentPtrVector &getChildren() const override; + const ArgumentPtrVector &getChildren() const noexcept final; void setChildren(const ArgumentPtrVector &childVect) override; diff --git a/include/fintamath/functions/arithmetic/Abs.hpp b/include/fintamath/functions/arithmetic/Abs.hpp index 2ab8df6c3..575248229 100644 --- a/include/fintamath/functions/arithmetic/Abs.hpp +++ b/include/fintamath/functions/arithmetic/Abs.hpp @@ -16,7 +16,7 @@ class Abs final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Abs) public: - std::string toString() const override { + std::string toString() const noexcept override { return "abs"; } diff --git a/include/fintamath/functions/arithmetic/Add.hpp b/include/fintamath/functions/arithmetic/Add.hpp index 310593bbd..5394a2e04 100644 --- a/include/fintamath/functions/arithmetic/Add.hpp +++ b/include/fintamath/functions/arithmetic/Add.hpp @@ -16,7 +16,7 @@ class Add final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Neg) public: - std::string toString() const override { + std::string toString() const noexcept override { return "-"; } diff --git a/include/fintamath/functions/arithmetic/Sign.hpp b/include/fintamath/functions/arithmetic/Sign.hpp index 475c8109d..723582e42 100644 --- a/include/fintamath/functions/arithmetic/Sign.hpp +++ b/include/fintamath/functions/arithmetic/Sign.hpp @@ -16,7 +16,7 @@ class Sign final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Sign) public: - std::string toString() const override { + std::string toString() const noexcept override { return "sign"; } diff --git a/include/fintamath/functions/arithmetic/Sub.hpp b/include/fintamath/functions/arithmetic/Sub.hpp index 91239303d..731a0f4b2 100644 --- a/include/fintamath/functions/arithmetic/Sub.hpp +++ b/include/fintamath/functions/arithmetic/Sub.hpp @@ -16,7 +16,7 @@ class Sub final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Max) public: - std::string toString() const override { + std::string toString() const noexcept override { return "max"; } diff --git a/include/fintamath/functions/calculus/Min.hpp b/include/fintamath/functions/calculus/Min.hpp index d42a205b7..a6fe2278b 100644 --- a/include/fintamath/functions/calculus/Min.hpp +++ b/include/fintamath/functions/calculus/Min.hpp @@ -16,7 +16,7 @@ class Min final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Min) public: - std::string toString() const override { + std::string toString() const noexcept override { return "min"; } diff --git a/include/fintamath/functions/comparison/Eqv.hpp b/include/fintamath/functions/comparison/Eqv.hpp index 3b115b6b3..6eb5b3efb 100644 --- a/include/fintamath/functions/comparison/Eqv.hpp +++ b/include/fintamath/functions/comparison/Eqv.hpp @@ -17,7 +17,7 @@ class Eqv final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Eqv) public: - std::string toString() const override { + std::string toString() const noexcept override { return "="; } diff --git a/include/fintamath/functions/comparison/Less.hpp b/include/fintamath/functions/comparison/Less.hpp index d720206c0..c15884b7b 100644 --- a/include/fintamath/functions/comparison/Less.hpp +++ b/include/fintamath/functions/comparison/Less.hpp @@ -17,7 +17,7 @@ class Less final : public IOperatorCRTP FINTAMATH_CLASS_BODY(Less) public: - std::string toString() const override { + std::string toString() const noexcept override { return "<"; } diff --git a/include/fintamath/functions/comparison/LessEqv.hpp b/include/fintamath/functions/comparison/LessEqv.hpp index 639d28a78..8440e6544 100644 --- a/include/fintamath/functions/comparison/LessEqv.hpp +++ b/include/fintamath/functions/comparison/LessEqv.hpp @@ -17,7 +17,7 @@ class LessEqv final : public IOperatorCRTP"; } diff --git a/include/fintamath/functions/comparison/MoreEqv.hpp b/include/fintamath/functions/comparison/MoreEqv.hpp index 954edfbfb..1f3ab4751 100644 --- a/include/fintamath/functions/comparison/MoreEqv.hpp +++ b/include/fintamath/functions/comparison/MoreEqv.hpp @@ -17,7 +17,7 @@ class MoreEqv final : public IOperatorCRTP="; } diff --git a/include/fintamath/functions/comparison/Neqv.hpp b/include/fintamath/functions/comparison/Neqv.hpp index 92324b196..863939aa1 100644 --- a/include/fintamath/functions/comparison/Neqv.hpp +++ b/include/fintamath/functions/comparison/Neqv.hpp @@ -17,7 +17,7 @@ class Neqv final : public IOperatorCRTP FINTAMATH_CLASS_BODY(Neqv) public: - std::string toString() const override { + std::string toString() const noexcept override { return "!="; } diff --git a/include/fintamath/functions/hyperbolic/Acosh.hpp b/include/fintamath/functions/hyperbolic/Acosh.hpp index ed67c828e..57ce07e2e 100644 --- a/include/fintamath/functions/hyperbolic/Acosh.hpp +++ b/include/fintamath/functions/hyperbolic/Acosh.hpp @@ -18,7 +18,7 @@ class Acosh final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Acosh) public: - std::string toString() const override { + std::string toString() const noexcept override { return "acosh"; } diff --git a/include/fintamath/functions/hyperbolic/Acoth.hpp b/include/fintamath/functions/hyperbolic/Acoth.hpp index 2b0aafe95..889529e01 100644 --- a/include/fintamath/functions/hyperbolic/Acoth.hpp +++ b/include/fintamath/functions/hyperbolic/Acoth.hpp @@ -18,7 +18,7 @@ class Acoth final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Acoth) public: - std::string toString() const override { + std::string toString() const noexcept override { return "acoth"; } diff --git a/include/fintamath/functions/hyperbolic/Acsch.hpp b/include/fintamath/functions/hyperbolic/Acsch.hpp index 523e6fd4c..e2d8fd8f0 100644 --- a/include/fintamath/functions/hyperbolic/Acsch.hpp +++ b/include/fintamath/functions/hyperbolic/Acsch.hpp @@ -18,7 +18,7 @@ class Acsch final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Acsch) public: - std::string toString() const override { + std::string toString() const noexcept override { return "acsch"; } diff --git a/include/fintamath/functions/hyperbolic/Asech.hpp b/include/fintamath/functions/hyperbolic/Asech.hpp index 7e1eba0dd..96e4ac154 100644 --- a/include/fintamath/functions/hyperbolic/Asech.hpp +++ b/include/fintamath/functions/hyperbolic/Asech.hpp @@ -18,7 +18,7 @@ class Asech final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Asech) public: - std::string toString() const override { + std::string toString() const noexcept override { return "asech"; } diff --git a/include/fintamath/functions/hyperbolic/Asinh.hpp b/include/fintamath/functions/hyperbolic/Asinh.hpp index 551861a8d..fea00703e 100644 --- a/include/fintamath/functions/hyperbolic/Asinh.hpp +++ b/include/fintamath/functions/hyperbolic/Asinh.hpp @@ -16,7 +16,7 @@ class Asinh final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Asinh) public: - std::string toString() const override { + std::string toString() const noexcept override { return "asinh"; } diff --git a/include/fintamath/functions/hyperbolic/Atanh.hpp b/include/fintamath/functions/hyperbolic/Atanh.hpp index a6cf9eb1d..4a604c1c8 100644 --- a/include/fintamath/functions/hyperbolic/Atanh.hpp +++ b/include/fintamath/functions/hyperbolic/Atanh.hpp @@ -18,7 +18,7 @@ class Atanh final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Atanh) public: - std::string toString() const override { + std::string toString() const noexcept override { return "atanh"; } diff --git a/include/fintamath/functions/hyperbolic/Cosh.hpp b/include/fintamath/functions/hyperbolic/Cosh.hpp index 56c28aea3..ad2f17b93 100644 --- a/include/fintamath/functions/hyperbolic/Cosh.hpp +++ b/include/fintamath/functions/hyperbolic/Cosh.hpp @@ -18,7 +18,7 @@ class Cosh final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Cosh) public: - std::string toString() const override { + std::string toString() const noexcept override { return "cosh"; } diff --git a/include/fintamath/functions/hyperbolic/Coth.hpp b/include/fintamath/functions/hyperbolic/Coth.hpp index ce9427450..dc066fac8 100644 --- a/include/fintamath/functions/hyperbolic/Coth.hpp +++ b/include/fintamath/functions/hyperbolic/Coth.hpp @@ -16,7 +16,7 @@ class Coth final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Coth) public: - std::string toString() const override { + std::string toString() const noexcept override { return "coth"; } diff --git a/include/fintamath/functions/hyperbolic/Csch.hpp b/include/fintamath/functions/hyperbolic/Csch.hpp index ee54f4c2b..833b4be4d 100644 --- a/include/fintamath/functions/hyperbolic/Csch.hpp +++ b/include/fintamath/functions/hyperbolic/Csch.hpp @@ -18,7 +18,7 @@ class Csch final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Csch) public: - std::string toString() const override { + std::string toString() const noexcept override { return "csch"; } diff --git a/include/fintamath/functions/hyperbolic/Sech.hpp b/include/fintamath/functions/hyperbolic/Sech.hpp index f6ed88872..842baf22a 100644 --- a/include/fintamath/functions/hyperbolic/Sech.hpp +++ b/include/fintamath/functions/hyperbolic/Sech.hpp @@ -18,7 +18,7 @@ class Sech final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Sech) public: - std::string toString() const override { + std::string toString() const noexcept override { return "sech"; } diff --git a/include/fintamath/functions/hyperbolic/Sinh.hpp b/include/fintamath/functions/hyperbolic/Sinh.hpp index 8331e9516..fb544a2fd 100644 --- a/include/fintamath/functions/hyperbolic/Sinh.hpp +++ b/include/fintamath/functions/hyperbolic/Sinh.hpp @@ -18,7 +18,7 @@ class Sinh final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Sinh) public: - std::string toString() const override { + std::string toString() const noexcept override { return "sinh"; } diff --git a/include/fintamath/functions/hyperbolic/Tanh.hpp b/include/fintamath/functions/hyperbolic/Tanh.hpp index fb2886ed3..d81b5bd48 100644 --- a/include/fintamath/functions/hyperbolic/Tanh.hpp +++ b/include/fintamath/functions/hyperbolic/Tanh.hpp @@ -16,7 +16,7 @@ class Tanh final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Tanh) public: - std::string toString() const override { + std::string toString() const noexcept override { return "tanh"; } diff --git a/include/fintamath/functions/logarithms/Lb.hpp b/include/fintamath/functions/logarithms/Lb.hpp index d90568704..b7d799c52 100644 --- a/include/fintamath/functions/logarithms/Lb.hpp +++ b/include/fintamath/functions/logarithms/Lb.hpp @@ -16,7 +16,7 @@ class Lb final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Lb) public: - std::string toString() const override { + std::string toString() const noexcept override { return "lb"; } diff --git a/include/fintamath/functions/logarithms/Lg.hpp b/include/fintamath/functions/logarithms/Lg.hpp index b3ff5c05f..698480860 100644 --- a/include/fintamath/functions/logarithms/Lg.hpp +++ b/include/fintamath/functions/logarithms/Lg.hpp @@ -16,7 +16,7 @@ class Lg final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Lg) public: - std::string toString() const override { + std::string toString() const noexcept override { return "lg"; } diff --git a/include/fintamath/functions/logarithms/Ln.hpp b/include/fintamath/functions/logarithms/Ln.hpp index fb05931e7..c4c5774b1 100644 --- a/include/fintamath/functions/logarithms/Ln.hpp +++ b/include/fintamath/functions/logarithms/Ln.hpp @@ -16,7 +16,7 @@ class Ln final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Ln) public: - std::string toString() const override { + std::string toString() const noexcept override { return "ln"; } diff --git a/include/fintamath/functions/logarithms/Log.hpp b/include/fintamath/functions/logarithms/Log.hpp index 12c6fb427..0a6d29343 100644 --- a/include/fintamath/functions/logarithms/Log.hpp +++ b/include/fintamath/functions/logarithms/Log.hpp @@ -19,7 +19,7 @@ class Log final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Log) public: - std::string toString() const override { + std::string toString() const noexcept override { return "log"; } diff --git a/include/fintamath/functions/logic/And.hpp b/include/fintamath/functions/logic/And.hpp index 19670ded5..b00679c8b 100644 --- a/include/fintamath/functions/logic/And.hpp +++ b/include/fintamath/functions/logic/And.hpp @@ -16,7 +16,7 @@ class And final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(And) public: - std::string toString() const override { + std::string toString() const noexcept override { return "&"; } diff --git a/include/fintamath/functions/logic/Equiv.hpp b/include/fintamath/functions/logic/Equiv.hpp index 2022f5e26..1ab891735 100644 --- a/include/fintamath/functions/logic/Equiv.hpp +++ b/include/fintamath/functions/logic/Equiv.hpp @@ -16,7 +16,7 @@ class Equiv final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Equiv) public: - std::string toString() const override { + std::string toString() const noexcept override { return "<->"; } diff --git a/include/fintamath/functions/logic/Impl.hpp b/include/fintamath/functions/logic/Impl.hpp index 8b8598b0a..99cfcb962 100644 --- a/include/fintamath/functions/logic/Impl.hpp +++ b/include/fintamath/functions/logic/Impl.hpp @@ -16,7 +16,7 @@ class Impl final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Impl) public: - std::string toString() const override { + std::string toString() const noexcept override { return "->"; } diff --git a/include/fintamath/functions/logic/Nequiv.hpp b/include/fintamath/functions/logic/Nequiv.hpp index 41f5fa9d9..c71a71dd6 100644 --- a/include/fintamath/functions/logic/Nequiv.hpp +++ b/include/fintamath/functions/logic/Nequiv.hpp @@ -16,7 +16,7 @@ class Nequiv final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Nequiv) public: - std::string toString() const override { + std::string toString() const noexcept override { return "!<->"; } diff --git a/include/fintamath/functions/logic/Not.hpp b/include/fintamath/functions/logic/Not.hpp index 768a75251..dacefbe17 100644 --- a/include/fintamath/functions/logic/Not.hpp +++ b/include/fintamath/functions/logic/Not.hpp @@ -16,7 +16,7 @@ class Not final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Not) public: - std::string toString() const override { + std::string toString() const noexcept override { return "~"; } diff --git a/include/fintamath/functions/logic/Or.hpp b/include/fintamath/functions/logic/Or.hpp index d49a3b0eb..6fc4c71d5 100644 --- a/include/fintamath/functions/logic/Or.hpp +++ b/include/fintamath/functions/logic/Or.hpp @@ -16,7 +16,7 @@ class Or final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Or) public: - std::string toString() const override { + std::string toString() const noexcept override { return "|"; } diff --git a/include/fintamath/functions/ntheory/Ceil.hpp b/include/fintamath/functions/ntheory/Ceil.hpp index cf41064f9..5c61aa2e5 100644 --- a/include/fintamath/functions/ntheory/Ceil.hpp +++ b/include/fintamath/functions/ntheory/Ceil.hpp @@ -16,7 +16,7 @@ class Ceil final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Ceil) public: - std::string toString() const override { + std::string toString() const noexcept override { return "ceil"; } diff --git a/include/fintamath/functions/ntheory/Floor.hpp b/include/fintamath/functions/ntheory/Floor.hpp index 9344450dd..ff12b109c 100644 --- a/include/fintamath/functions/ntheory/Floor.hpp +++ b/include/fintamath/functions/ntheory/Floor.hpp @@ -16,7 +16,7 @@ class Floor final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Floor) public: - std::string toString() const override { + std::string toString() const noexcept override { return "floor"; } diff --git a/include/fintamath/functions/ntheory/Mod.hpp b/include/fintamath/functions/ntheory/Mod.hpp index a581023b1..4aaa83c20 100644 --- a/include/fintamath/functions/ntheory/Mod.hpp +++ b/include/fintamath/functions/ntheory/Mod.hpp @@ -16,7 +16,7 @@ class Mod final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Mod) public: - std::string toString() const override { + std::string toString() const noexcept override { return "mod"; } diff --git a/include/fintamath/functions/other/Comma.hpp b/include/fintamath/functions/other/Comma.hpp index 7ac4fd0b1..694b56b86 100644 --- a/include/fintamath/functions/other/Comma.hpp +++ b/include/fintamath/functions/other/Comma.hpp @@ -15,7 +15,7 @@ class Comma final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Deg) public: - std::string toString() const override { + std::string toString() const noexcept override { return "deg"; } diff --git a/include/fintamath/functions/other/Factorial.hpp b/include/fintamath/functions/other/Factorial.hpp index 4305359b5..ce0f85d30 100644 --- a/include/fintamath/functions/other/Factorial.hpp +++ b/include/fintamath/functions/other/Factorial.hpp @@ -28,7 +28,7 @@ class Factorial final : public IOperatorCRTP { setOrder(inOrder); } - std::string toString() const override { + std::string toString() const noexcept override { return std::string(order, '!'); } diff --git a/include/fintamath/functions/other/Index.hpp b/include/fintamath/functions/other/Index.hpp index bea96eec9..d51457a4f 100644 --- a/include/fintamath/functions/other/Index.hpp +++ b/include/fintamath/functions/other/Index.hpp @@ -17,7 +17,7 @@ class Index final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Index) public: - std::string toString() const override { + std::string toString() const noexcept override { return "_"; } diff --git a/include/fintamath/functions/other/Percent.hpp b/include/fintamath/functions/other/Percent.hpp index ad55fcf73..a8417aa02 100644 --- a/include/fintamath/functions/other/Percent.hpp +++ b/include/fintamath/functions/other/Percent.hpp @@ -16,7 +16,7 @@ class Percent final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Percent) public: - std::string toString() const override { + std::string toString() const noexcept override { return "%"; } diff --git a/include/fintamath/functions/powers/Exp.hpp b/include/fintamath/functions/powers/Exp.hpp index c4e389b0b..db9aea56a 100644 --- a/include/fintamath/functions/powers/Exp.hpp +++ b/include/fintamath/functions/powers/Exp.hpp @@ -16,7 +16,7 @@ class Exp final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Exp) public: - std::string toString() const override { + std::string toString() const noexcept override { return "exp"; } diff --git a/include/fintamath/functions/powers/Pow.hpp b/include/fintamath/functions/powers/Pow.hpp index 9c34f396d..a5b8bb869 100644 --- a/include/fintamath/functions/powers/Pow.hpp +++ b/include/fintamath/functions/powers/Pow.hpp @@ -21,7 +21,7 @@ class Pow final : public IOperatorCRTP { FINTAMATH_CLASS_BODY(Pow) public: - std::string toString() const override { + std::string toString() const noexcept override { return "^"; } diff --git a/include/fintamath/functions/powers/PowFunction.hpp b/include/fintamath/functions/powers/PowFunction.hpp index f071108e0..7dcb3ec66 100644 --- a/include/fintamath/functions/powers/PowFunction.hpp +++ b/include/fintamath/functions/powers/PowFunction.hpp @@ -15,7 +15,7 @@ class PowFunction final : public IFunctionCRTP { using RootToFactorMap = std::map; public: - std::string toString() const override { + std::string toString() const noexcept override { return "root"; } diff --git a/include/fintamath/functions/powers/Sqr.hpp b/include/fintamath/functions/powers/Sqr.hpp index a53051db4..910a3e323 100644 --- a/include/fintamath/functions/powers/Sqr.hpp +++ b/include/fintamath/functions/powers/Sqr.hpp @@ -16,7 +16,7 @@ class Sqr final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Sqr) public: - std::string toString() const override { + std::string toString() const noexcept override { return "sqr"; } diff --git a/include/fintamath/functions/powers/Sqrt.hpp b/include/fintamath/functions/powers/Sqrt.hpp index 1d360cb8a..f87cbb5e8 100644 --- a/include/fintamath/functions/powers/Sqrt.hpp +++ b/include/fintamath/functions/powers/Sqrt.hpp @@ -16,7 +16,7 @@ class Sqrt final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Sqrt) public: - std::string toString() const override { + std::string toString() const noexcept override { return "sqrt"; } diff --git a/include/fintamath/functions/trigonometry/Acos.hpp b/include/fintamath/functions/trigonometry/Acos.hpp index 65eea4330..a38647428 100644 --- a/include/fintamath/functions/trigonometry/Acos.hpp +++ b/include/fintamath/functions/trigonometry/Acos.hpp @@ -18,7 +18,7 @@ class Acos final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Acos) public: - std::string toString() const override { + std::string toString() const noexcept override { return "acos"; } diff --git a/include/fintamath/functions/trigonometry/Acot.hpp b/include/fintamath/functions/trigonometry/Acot.hpp index 6729bb50e..4f5dd9a23 100644 --- a/include/fintamath/functions/trigonometry/Acot.hpp +++ b/include/fintamath/functions/trigonometry/Acot.hpp @@ -16,7 +16,7 @@ class Acot final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Acot) public: - std::string toString() const override { + std::string toString() const noexcept override { return "acot"; } diff --git a/include/fintamath/functions/trigonometry/Acsc.hpp b/include/fintamath/functions/trigonometry/Acsc.hpp index 816199d74..f3610176f 100644 --- a/include/fintamath/functions/trigonometry/Acsc.hpp +++ b/include/fintamath/functions/trigonometry/Acsc.hpp @@ -18,7 +18,7 @@ class Acsc final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Acsc) public: - std::string toString() const override { + std::string toString() const noexcept override { return "acsc"; } diff --git a/include/fintamath/functions/trigonometry/Asec.hpp b/include/fintamath/functions/trigonometry/Asec.hpp index 85030f466..a0c3080ce 100644 --- a/include/fintamath/functions/trigonometry/Asec.hpp +++ b/include/fintamath/functions/trigonometry/Asec.hpp @@ -18,7 +18,7 @@ class Asec final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Asec) public: - std::string toString() const override { + std::string toString() const noexcept override { return "asec"; } diff --git a/include/fintamath/functions/trigonometry/Asin.hpp b/include/fintamath/functions/trigonometry/Asin.hpp index df451eb8b..c8c210060 100644 --- a/include/fintamath/functions/trigonometry/Asin.hpp +++ b/include/fintamath/functions/trigonometry/Asin.hpp @@ -18,7 +18,7 @@ class Asin final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Asin) public: - std::string toString() const override { + std::string toString() const noexcept override { return "asin"; } diff --git a/include/fintamath/functions/trigonometry/Atan.hpp b/include/fintamath/functions/trigonometry/Atan.hpp index 86f70c35d..b0e21e889 100644 --- a/include/fintamath/functions/trigonometry/Atan.hpp +++ b/include/fintamath/functions/trigonometry/Atan.hpp @@ -16,7 +16,7 @@ class Atan final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Atan) public: - std::string toString() const override { + std::string toString() const noexcept override { return "atan"; } diff --git a/include/fintamath/functions/trigonometry/Cos.hpp b/include/fintamath/functions/trigonometry/Cos.hpp index 29f5c7193..b390c8364 100644 --- a/include/fintamath/functions/trigonometry/Cos.hpp +++ b/include/fintamath/functions/trigonometry/Cos.hpp @@ -18,7 +18,7 @@ class Cos final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Cos) public: - std::string toString() const override { + std::string toString() const noexcept override { return "cos"; } diff --git a/include/fintamath/functions/trigonometry/Cot.hpp b/include/fintamath/functions/trigonometry/Cot.hpp index dbb785145..5ff971de1 100644 --- a/include/fintamath/functions/trigonometry/Cot.hpp +++ b/include/fintamath/functions/trigonometry/Cot.hpp @@ -18,7 +18,7 @@ class Cot final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Cot) public: - std::string toString() const override { + std::string toString() const noexcept override { return "cot"; } diff --git a/include/fintamath/functions/trigonometry/Csc.hpp b/include/fintamath/functions/trigonometry/Csc.hpp index b459c02d2..6bf24f1e6 100644 --- a/include/fintamath/functions/trigonometry/Csc.hpp +++ b/include/fintamath/functions/trigonometry/Csc.hpp @@ -18,7 +18,7 @@ class Csc final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Csc) public: - std::string toString() const override { + std::string toString() const noexcept override { return "csc"; } diff --git a/include/fintamath/functions/trigonometry/Sec.hpp b/include/fintamath/functions/trigonometry/Sec.hpp index 90d31543c..330c4d9f5 100644 --- a/include/fintamath/functions/trigonometry/Sec.hpp +++ b/include/fintamath/functions/trigonometry/Sec.hpp @@ -18,7 +18,7 @@ class Sec final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Sec) public: - std::string toString() const override { + std::string toString() const noexcept override { return "sec"; } diff --git a/include/fintamath/functions/trigonometry/Sin.hpp b/include/fintamath/functions/trigonometry/Sin.hpp index 34c761adc..c626c26fc 100644 --- a/include/fintamath/functions/trigonometry/Sin.hpp +++ b/include/fintamath/functions/trigonometry/Sin.hpp @@ -18,7 +18,7 @@ class Sin final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Sin) public: - std::string toString() const override { + std::string toString() const noexcept override { return "sin"; } diff --git a/include/fintamath/functions/trigonometry/Tan.hpp b/include/fintamath/functions/trigonometry/Tan.hpp index 0ef5bde12..4bbe447f4 100644 --- a/include/fintamath/functions/trigonometry/Tan.hpp +++ b/include/fintamath/functions/trigonometry/Tan.hpp @@ -18,7 +18,7 @@ class Tan final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(Tan) public: - std::string toString() const override { + std::string toString() const noexcept override { return "tan"; } diff --git a/include/fintamath/literals/Boolean.hpp b/include/fintamath/literals/Boolean.hpp index 7c752d389..9063f00c4 100644 --- a/include/fintamath/literals/Boolean.hpp +++ b/include/fintamath/literals/Boolean.hpp @@ -19,7 +19,7 @@ class Boolean final : public ILiteralCRTP { Boolean(const Bool val) : name(val ? trueStr : falseStr) { } - std::string toString() const override; + std::string toString() const noexcept override; explicit operator bool() const; diff --git a/include/fintamath/literals/Variable.hpp b/include/fintamath/literals/Variable.hpp index a879e6fb9..7e7cfd916 100644 --- a/include/fintamath/literals/Variable.hpp +++ b/include/fintamath/literals/Variable.hpp @@ -16,7 +16,7 @@ class Variable final : public ILiteralCRTP { explicit Variable(std::string inName, Integer inIndex); - std::string toString() const override; + std::string toString() const noexcept override; private: std::string name; diff --git a/include/fintamath/literals/constants/ComplexInf.hpp b/include/fintamath/literals/constants/ComplexInf.hpp index 80ae57ed1..07f8ba8f8 100644 --- a/include/fintamath/literals/constants/ComplexInf.hpp +++ b/include/fintamath/literals/constants/ComplexInf.hpp @@ -14,7 +14,7 @@ class ComplexInf final : public IConstantCRTP { FINTAMATH_CLASS_BODY(ComplexInf) public: - std::string toString() const override { + std::string toString() const noexcept override { return "ComplexInf"; } diff --git a/include/fintamath/literals/constants/E.hpp b/include/fintamath/literals/constants/E.hpp index 50eb52f50..12e1fc412 100644 --- a/include/fintamath/literals/constants/E.hpp +++ b/include/fintamath/literals/constants/E.hpp @@ -14,7 +14,7 @@ class E final : public IConstantCRTP { FINTAMATH_CLASS_BODY(E) public: - std::string toString() const override { + std::string toString() const noexcept override { return "E"; } diff --git a/include/fintamath/literals/constants/False.hpp b/include/fintamath/literals/constants/False.hpp index 44f565456..dd2275365 100644 --- a/include/fintamath/literals/constants/False.hpp +++ b/include/fintamath/literals/constants/False.hpp @@ -14,7 +14,7 @@ class False final : public IConstantCRTP { FINTAMATH_CLASS_BODY(False) public: - std::string toString() const override { + std::string toString() const noexcept override { return Boolean(false).toString(); } diff --git a/include/fintamath/literals/constants/I.hpp b/include/fintamath/literals/constants/I.hpp index 23805d11d..ea80ccf55 100644 --- a/include/fintamath/literals/constants/I.hpp +++ b/include/fintamath/literals/constants/I.hpp @@ -14,7 +14,7 @@ class I final : public IConstantCRTP { FINTAMATH_CLASS_BODY(I) public: - std::string toString() const override { + std::string toString() const noexcept override { return "I"; } diff --git a/include/fintamath/literals/constants/Inf.hpp b/include/fintamath/literals/constants/Inf.hpp index 09f0f7141..2b46de48d 100644 --- a/include/fintamath/literals/constants/Inf.hpp +++ b/include/fintamath/literals/constants/Inf.hpp @@ -14,7 +14,7 @@ class Inf final : public IConstantCRTP { FINTAMATH_CLASS_BODY(Inf) public: - std::string toString() const override { + std::string toString() const noexcept override { return "Inf"; } diff --git a/include/fintamath/literals/constants/NegInf.hpp b/include/fintamath/literals/constants/NegInf.hpp index aa2aea146..5378fcec9 100644 --- a/include/fintamath/literals/constants/NegInf.hpp +++ b/include/fintamath/literals/constants/NegInf.hpp @@ -14,7 +14,7 @@ class NegInf final : public IConstantCRTP { FINTAMATH_CLASS_BODY(NegInf) public: - std::string toString() const override { + std::string toString() const noexcept override { return "-Inf"; } diff --git a/include/fintamath/literals/constants/Pi.hpp b/include/fintamath/literals/constants/Pi.hpp index b586cfc78..603c33eb2 100644 --- a/include/fintamath/literals/constants/Pi.hpp +++ b/include/fintamath/literals/constants/Pi.hpp @@ -14,7 +14,7 @@ class Pi final : public IConstantCRTP { FINTAMATH_CLASS_BODY(Pi) public: - std::string toString() const override { + std::string toString() const noexcept override { return "Pi"; } diff --git a/include/fintamath/literals/constants/True.hpp b/include/fintamath/literals/constants/True.hpp index 5fc092b39..fe5df521e 100644 --- a/include/fintamath/literals/constants/True.hpp +++ b/include/fintamath/literals/constants/True.hpp @@ -14,7 +14,7 @@ class True final : public IConstantCRTP { FINTAMATH_CLASS_BODY(True) public: - std::string toString() const override { + std::string toString() const noexcept override { return Boolean(true).toString(); } diff --git a/include/fintamath/literals/constants/Undefined.hpp b/include/fintamath/literals/constants/Undefined.hpp index 116f4427d..a85cd1fb1 100644 --- a/include/fintamath/literals/constants/Undefined.hpp +++ b/include/fintamath/literals/constants/Undefined.hpp @@ -14,7 +14,7 @@ class Undefined final : public IConstantCRTP { FINTAMATH_CLASS_BODY(Undefined) public: - std::string toString() const override { + std::string toString() const noexcept override { return "Undefined"; } diff --git a/include/fintamath/numbers/Complex.hpp b/include/fintamath/numbers/Complex.hpp index e34bfde6a..895f48e12 100644 --- a/include/fintamath/numbers/Complex.hpp +++ b/include/fintamath/numbers/Complex.hpp @@ -42,9 +42,9 @@ class Complex final : public INumberCRTP { Complex(int64_t rhs); - std::string toString() const override; + std::string toString() const noexcept override; - std::unique_ptr toMinimalObject() const override; + std::unique_ptr toMinimalObject() const noexcept override; bool isPrecise() const override; @@ -55,7 +55,7 @@ class Complex final : public INumberCRTP { const INumber &imag() const; protected: - bool equals(const Complex &rhs) const override; + bool equals(const Complex &rhs) const noexcept override; std::strong_ordering compare(const Complex &rhs) const override; diff --git a/include/fintamath/numbers/Integer.hpp b/include/fintamath/numbers/Integer.hpp index 27e13929b..68f00f3fc 100644 --- a/include/fintamath/numbers/Integer.hpp +++ b/include/fintamath/numbers/Integer.hpp @@ -34,7 +34,7 @@ class Integer final : public INumberCRTP { Integer(int64_t val); - std::string toString() const override; + std::string toString() const noexcept override; int sign() const; @@ -80,7 +80,7 @@ class Integer final : public INumberCRTP { Integer operator--(int); protected: - bool equals(const Integer &rhs) const override; + bool equals(const Integer &rhs) const noexcept override; std::strong_ordering compare(const Integer &rhs) const override; diff --git a/include/fintamath/numbers/Rational.hpp b/include/fintamath/numbers/Rational.hpp index 181a8a563..8037cc552 100644 --- a/include/fintamath/numbers/Rational.hpp +++ b/include/fintamath/numbers/Rational.hpp @@ -28,9 +28,9 @@ class Rational final : public INumberCRTP { Rational(int64_t rhs); - std::string toString() const override; + std::string toString() const noexcept override; - std::unique_ptr toMinimalObject() const override; + std::unique_ptr toMinimalObject() const noexcept override; int sign() const; @@ -39,7 +39,7 @@ class Rational final : public INumberCRTP { const Integer &denominator() const; protected: - bool equals(const Rational &rhs) const override; + bool equals(const Rational &rhs) const noexcept override; std::strong_ordering compare(const Rational &rhs) const override; diff --git a/include/fintamath/numbers/Real.hpp b/include/fintamath/numbers/Real.hpp index ffa942fc5..c040a4d02 100644 --- a/include/fintamath/numbers/Real.hpp +++ b/include/fintamath/numbers/Real.hpp @@ -51,9 +51,9 @@ class Real final : public INumberCRTP { Real(int64_t val); - std::string toString() const override; + std::string toString() const noexcept override; - std::string toString(unsigned precision) const; + std::string toString(unsigned precision) const noexcept; bool isPrecise() const override; @@ -74,9 +74,9 @@ class Real final : public INumberCRTP { static void setPrecision(unsigned precision); protected: - bool equals(const Real &rhs) const override; + bool equals(const Real &rhs) const noexcept override; - bool equalsAbstract(const IMathObject &rhs) const override; + bool equalsAbstract(const IMathObject &rhs) const noexcept override; std::strong_ordering compare(const Real &rhs) const override; @@ -99,8 +99,6 @@ class Real final : public INumberCRTP { void updatePrecision(const Real &rhs); - void validateNewPrecision(unsigned precision) const; - private: Backend backend; diff --git a/src/fintamath/core/MathObjectClass.cpp b/src/fintamath/core/MathObjectClass.cpp index eb073ac6f..e10ee9b06 100644 --- a/src/fintamath/core/MathObjectClass.cpp +++ b/src/fintamath/core/MathObjectClass.cpp @@ -2,7 +2,7 @@ namespace fintamath { -std::strong_ordering MathObjectClass::operator<=>(const MathObjectClass rhs) const { +std::strong_ordering MathObjectClass::operator<=>(const MathObjectClass rhs) const noexcept { const Id lhsId = getId(); const Id rhsId = rhs.getId(); @@ -11,12 +11,12 @@ std::strong_ordering MathObjectClass::operator<=>(const MathObjectClass rhs) con : name <=> rhs.name; } -std::optional MathObjectClass::getParent() const { +std::optional MathObjectClass::getParent() const noexcept { const auto iter = getChildToParentMap().find(name); return iter != getChildToParentMap().end() ? iter->second : std::optional{}; } -const MathObjectClass::Children &MathObjectClass::getChildren(const bool recursive) const { +const MathObjectClass::Children &MathObjectClass::getChildren(const bool recursive) const noexcept { if (recursive) { return getParentToRecursiveChildrenMap()[name]; } @@ -24,27 +24,27 @@ const MathObjectClass::Children &MathObjectClass::getChildren(const bool recursi return getParentToChildrenMap()[name]; } -MathObjectClass::Id MathObjectClass::getId() const { +MathObjectClass::Id MathObjectClass::getId() const noexcept { const auto classToId = getClassToIdMap().find(*this); return classToId != getClassToIdMap().end() ? classToId->second : 0; } -MathObjectClass::ClassToIdMap &MathObjectClass::getClassToIdMap() { +MathObjectClass::ClassToIdMap &MathObjectClass::getClassToIdMap() noexcept { static ClassToIdMap map; return map; } -MathObjectClass::ChildToParentMap &MathObjectClass::getChildToParentMap() { +MathObjectClass::ChildToParentMap &MathObjectClass::getChildToParentMap() noexcept { static ChildToParentMap map; return map; } -MathObjectClass::ParentToChildrenMap &MathObjectClass::getParentToChildrenMap() { +MathObjectClass::ParentToChildrenMap &MathObjectClass::getParentToChildrenMap() noexcept { static ParentToChildrenMap map; return map; } -MathObjectClass::ParentToChildrenMap &MathObjectClass::getParentToRecursiveChildrenMap() { +MathObjectClass::ParentToChildrenMap &MathObjectClass::getParentToRecursiveChildrenMap() noexcept { static ParentToChildrenMap map; return map; } diff --git a/src/fintamath/core/Tokenizer.cpp b/src/fintamath/core/Tokenizer.cpp index 0f208c099..f8884ea69 100644 --- a/src/fintamath/core/Tokenizer.cpp +++ b/src/fintamath/core/Tokenizer.cpp @@ -36,7 +36,7 @@ TokenVector Tokenizer::tokenize(std::string str) { return tokens; } -void Tokenizer::registerToken(const Token &token) { +void Tokenizer::registerToken(const Token &token) noexcept { auto &tokens = getRegisteredTokens(); tokens.insert(std::ranges::upper_bound(tokens, token, [](const Token &lhs, const Token &rhs) { return lhs.size() > rhs.size(); @@ -98,7 +98,7 @@ bool Tokenizer::isSpace(const char ch) { return ch == ' '; } -TokenVector &Tokenizer::getRegisteredTokens() { +TokenVector &Tokenizer::getRegisteredTokens() noexcept { static TokenVector registeredTokens; return registeredTokens; } diff --git a/src/fintamath/expressions/Expression.cpp b/src/fintamath/expressions/Expression.cpp index 9214a8cdc..8c6a2698c 100644 --- a/src/fintamath/expressions/Expression.cpp +++ b/src/fintamath/expressions/Expression.cpp @@ -56,7 +56,7 @@ Expression::Expression(const IMathObject &obj) : Expression(obj.clone()) { Expression::Expression(const int64_t val) : child(Integer(val).clone()) { } -std::string Expression::toString() const { +std::string Expression::toString() const noexcept { simplifyMutable(); return stringCached; } @@ -77,12 +77,12 @@ Expression approximate(const Expression &rhs, const unsigned precision) { return approxExpr; } -const std::shared_ptr &Expression::getFunction() const { +const std::shared_ptr &Expression::getFunction() const noexcept { static const std::shared_ptr func; return func; } -const ArgumentPtrVector &Expression::getChildren() const { +const ArgumentPtrVector &Expression::getChildren() const noexcept { simplifyMutable(); childrenCached.front() = child; return childrenCached; diff --git a/src/fintamath/expressions/FunctionExpression.cpp b/src/fintamath/expressions/FunctionExpression.cpp index 82a16c578..3a0b9ab05 100644 --- a/src/fintamath/expressions/FunctionExpression.cpp +++ b/src/fintamath/expressions/FunctionExpression.cpp @@ -22,7 +22,7 @@ FunctionExpression::FunctionExpression(const IFunction &inFunc, ArgumentPtrVecto } } -std::string FunctionExpression::toString() const { +std::string FunctionExpression::toString() const noexcept { if (const auto oper = cast(func)) { if (oper->getPriority() == IOperator::Priority::PostfixUnary) { return postfixUnaryOperatorToString(*oper, children.front()); @@ -38,11 +38,11 @@ std::string FunctionExpression::toString() const { return functionToString(*func, children); } -const std::shared_ptr &FunctionExpression::getFunction() const { +const std::shared_ptr &FunctionExpression::getFunction() const noexcept { return func; } -const ArgumentPtrVector &FunctionExpression::getChildren() const { +const ArgumentPtrVector &FunctionExpression::getChildren() const noexcept { return children; } diff --git a/src/fintamath/expressions/FunctionExpression.hpp b/src/fintamath/expressions/FunctionExpression.hpp index 2e0640e0a..8c2f610ed 100644 --- a/src/fintamath/expressions/FunctionExpression.hpp +++ b/src/fintamath/expressions/FunctionExpression.hpp @@ -16,11 +16,11 @@ class FunctionExpression final : public IExpressionCRTP { public: explicit FunctionExpression(const IFunction &inFunc, ArgumentPtrVector inChildren); - std::string toString() const override; + std::string toString() const noexcept override; - const std::shared_ptr &getFunction() const override; + const std::shared_ptr &getFunction() const noexcept override; - const ArgumentPtrVector &getChildren() const override; + const ArgumentPtrVector &getChildren() const noexcept override; void setChildren(const ArgumentPtrVector &childVect) override; diff --git a/src/fintamath/expressions/IExpression.cpp b/src/fintamath/expressions/IExpression.cpp index 6be1d77ea..2f2ded2df 100644 --- a/src/fintamath/expressions/IExpression.cpp +++ b/src/fintamath/expressions/IExpression.cpp @@ -80,11 +80,11 @@ void IExpression::setVariables(const std::vector IExpression::toMinimalObject() const { +std::unique_ptr IExpression::toMinimalObject() const noexcept { return simplify()->clone(); } -const std::shared_ptr &IExpression::getOutputFunction() const { +const std::shared_ptr &IExpression::getOutputFunction() const noexcept { return getFunction(); } diff --git a/src/fintamath/expressions/binary/CompExpr.cpp b/src/fintamath/expressions/binary/CompExpr.cpp index 89c539209..f594da87f 100644 --- a/src/fintamath/expressions/binary/CompExpr.cpp +++ b/src/fintamath/expressions/binary/CompExpr.cpp @@ -40,7 +40,7 @@ CompExpr::CompExpr(const IOperator &inOper, ArgumentPtr inLhsChild, ArgumentPtr : IBinaryExpressionCRTP(inOper, std::move(inLhsChild), std::move(inRhsChild)) { } -std::string CompExpr::toString() const { +std::string CompExpr::toString() const noexcept { if (isSolution) { if (const auto lhsExpr = cast(lhsChild); lhsExpr && diff --git a/src/fintamath/expressions/binary/CompExpr.hpp b/src/fintamath/expressions/binary/CompExpr.hpp index 225bfc9d7..1be77100c 100644 --- a/src/fintamath/expressions/binary/CompExpr.hpp +++ b/src/fintamath/expressions/binary/CompExpr.hpp @@ -18,7 +18,7 @@ class CompExpr final : public IBinaryExpressionCRTP { public: CompExpr(const IOperator &inOper, ArgumentPtr inLhsChild, ArgumentPtr inRhsChild); - std::string toString() const override; + std::string toString() const noexcept override; void markAsSolution(); diff --git a/src/fintamath/expressions/binary/DivExpr.cpp b/src/fintamath/expressions/binary/DivExpr.cpp index a269809a6..dff152c58 100644 --- a/src/fintamath/expressions/binary/DivExpr.cpp +++ b/src/fintamath/expressions/binary/DivExpr.cpp @@ -45,7 +45,7 @@ DivExpr::DivExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild) : IBinaryExpressionCRTP(Div{}, std::move(inLhsChild), std::move(inRhsChild)) { } -std::string DivExpr::toString() const { +std::string DivExpr::toString() const noexcept { if (isNegated(lhsChild)) { return negExpr(divExpr(detail::negate(lhsChild), rhsChild))->toString(); } diff --git a/src/fintamath/expressions/binary/DivExpr.hpp b/src/fintamath/expressions/binary/DivExpr.hpp index 34ff07184..a9054620e 100644 --- a/src/fintamath/expressions/binary/DivExpr.hpp +++ b/src/fintamath/expressions/binary/DivExpr.hpp @@ -17,7 +17,7 @@ class DivExpr final : public IBinaryExpressionCRTP { public: explicit DivExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild); - std::string toString() const override; + std::string toString() const noexcept override; protected: SimplifyFunctionVector getFunctionsForPreSimplify() const override; diff --git a/src/fintamath/expressions/binary/LogExpr.cpp b/src/fintamath/expressions/binary/LogExpr.cpp index 236174e10..f07fad748 100644 --- a/src/fintamath/expressions/binary/LogExpr.cpp +++ b/src/fintamath/expressions/binary/LogExpr.cpp @@ -28,7 +28,7 @@ LogExpr::LogExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild) : IBinaryExpressionCRTP(Log{}, std::move(inLhsChild), std::move(inRhsChild)) { } -std::string LogExpr::toString() const { +std::string LogExpr::toString() const noexcept { if (*lhsChild == E{}) { return functionToString(Ln{}, {rhsChild}); } @@ -36,7 +36,7 @@ std::string LogExpr::toString() const { return IBinaryExpression::toString(); } -const std::shared_ptr &LogExpr::getOutputFunction() const { +const std::shared_ptr &LogExpr::getOutputFunction() const noexcept { static const std::shared_ptr ln = std::make_shared(); if (*lhsChild == E{}) { diff --git a/src/fintamath/expressions/binary/LogExpr.hpp b/src/fintamath/expressions/binary/LogExpr.hpp index 57bc9b178..5ac2f2932 100644 --- a/src/fintamath/expressions/binary/LogExpr.hpp +++ b/src/fintamath/expressions/binary/LogExpr.hpp @@ -17,9 +17,9 @@ class LogExpr final : public IBinaryExpressionCRTP { public: explicit LogExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild); - std::string toString() const override; + std::string toString() const noexcept override; - const std::shared_ptr &getOutputFunction() const override; + const std::shared_ptr &getOutputFunction() const noexcept override; protected: ArgumentPtr approximate() const override; diff --git a/src/fintamath/expressions/binary/PowExpr.cpp b/src/fintamath/expressions/binary/PowExpr.cpp index de3616aba..0c5f4b204 100644 --- a/src/fintamath/expressions/binary/PowExpr.cpp +++ b/src/fintamath/expressions/binary/PowExpr.cpp @@ -43,7 +43,7 @@ PowExpr::PowExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild) : IBinaryExpressionCRTP(Pow{}, std::move(inLhsChild), std::move(inRhsChild)) { } -std::string PowExpr::toString() const { +std::string PowExpr::toString() const noexcept { if (const auto rhsChildRat = cast(rhsChild)) { const Integer &numerator = rhsChildRat->numerator(); const Integer &denominator = rhsChildRat->denominator(); @@ -68,7 +68,7 @@ std::string PowExpr::toString() const { return IBinaryExpression::toString(); } -const std::shared_ptr &PowExpr::getOutputFunction() const { +const std::shared_ptr &PowExpr::getOutputFunction() const noexcept { static const std::shared_ptr sqrt = std::make_shared(); static const std::shared_ptr root = std::make_shared(); @@ -137,7 +137,7 @@ PowExpr::SimplifyFunctionVector PowExpr::getFunctionsForPostSimplify() const { Integer PowExpr::generateFirstNum(const Integer &countOfOne) { Integer n = 0; - repeat(countOfOne, [&]() { + repeat(countOfOne, [&] { n <<= 1; n |= 1; }); @@ -193,7 +193,7 @@ ArgumentPtr PowExpr::sumPolynomSimplify(const ArgumentPtr &expr, const Integer & ArgumentPtrVector newChildren; - repeat(combins, [&]() { + repeat(combins, [&] { std::vector vectOfPows = getPartition(bitNumber, Integer(variableCount)); bitNumber = generateNextNumber(bitNumber); diff --git a/src/fintamath/expressions/binary/PowExpr.hpp b/src/fintamath/expressions/binary/PowExpr.hpp index d271c4dad..8538f5b80 100644 --- a/src/fintamath/expressions/binary/PowExpr.hpp +++ b/src/fintamath/expressions/binary/PowExpr.hpp @@ -18,9 +18,9 @@ class PowExpr final : public IBinaryExpressionCRTP { public: explicit PowExpr(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild); - std::string toString() const override; + std::string toString() const noexcept override; - const std::shared_ptr &getOutputFunction() const override; + const std::shared_ptr &getOutputFunction() const noexcept override; protected: ArgumentPtr approximate() const override; diff --git a/src/fintamath/expressions/interfaces/IBinaryExpression.cpp b/src/fintamath/expressions/interfaces/IBinaryExpression.cpp index 650cfabd7..70f8734e4 100644 --- a/src/fintamath/expressions/interfaces/IBinaryExpression.cpp +++ b/src/fintamath/expressions/interfaces/IBinaryExpression.cpp @@ -22,7 +22,7 @@ IBinaryExpression::IBinaryExpression(const IFunction &inFunc, ArgumentPtr lhs, A rhsChild(std::move(rhs)) { } -std::string IBinaryExpression::toString() const { +std::string IBinaryExpression::toString() const noexcept { if (const auto oper = cast(func)) { return binaryOperatorToString(*oper, lhsChild, rhsChild); } @@ -30,11 +30,11 @@ std::string IBinaryExpression::toString() const { return functionToString(*func, {lhsChild, rhsChild}); } -const std::shared_ptr &IBinaryExpression::getFunction() const { +const std::shared_ptr &IBinaryExpression::getFunction() const noexcept { return func; } -const ArgumentPtrVector &IBinaryExpression::getChildren() const { +const ArgumentPtrVector &IBinaryExpression::getChildren() const noexcept { childrenCached.front() = lhsChild; childrenCached.back() = rhsChild; return childrenCached; diff --git a/src/fintamath/expressions/interfaces/IPolynomExpression.cpp b/src/fintamath/expressions/interfaces/IPolynomExpression.cpp index bba48aab8..2d897a66e 100644 --- a/src/fintamath/expressions/interfaces/IPolynomExpression.cpp +++ b/src/fintamath/expressions/interfaces/IPolynomExpression.cpp @@ -30,15 +30,15 @@ IPolynomExpression::IPolynomExpression(const IFunction &inFunc, ArgumentPtrVecto children(std::move(args)) { } -const std::shared_ptr &IPolynomExpression::getFunction() const { +const std::shared_ptr &IPolynomExpression::getFunction() const noexcept { return func; } -const ArgumentPtrVector &IPolynomExpression::getChildren() const { +const ArgumentPtrVector &IPolynomExpression::getChildren() const noexcept { return children; } -std::string IPolynomExpression::toString() const { +std::string IPolynomExpression::toString() const noexcept { const auto oper = cast(func); if (!oper) { return functionToString(*func, children); diff --git a/src/fintamath/expressions/interfaces/IUnaryExpression.cpp b/src/fintamath/expressions/interfaces/IUnaryExpression.cpp index eea6dd31f..e8c9f0983 100644 --- a/src/fintamath/expressions/interfaces/IUnaryExpression.cpp +++ b/src/fintamath/expressions/interfaces/IUnaryExpression.cpp @@ -21,7 +21,7 @@ IUnaryExpression::IUnaryExpression(const IFunction &inFunc, ArgumentPtr rhs) child(std::move(rhs)) { } -std::string IUnaryExpression::toString() const { +std::string IUnaryExpression::toString() const noexcept { if (const auto oper = cast(func)) { if (oper->getPriority() == IOperator::Priority::PostfixUnary) { return detail::postfixUnaryOperatorToString(*oper, child); @@ -33,11 +33,11 @@ std::string IUnaryExpression::toString() const { return detail::functionToString(*func, {child}); } -const std::shared_ptr &IUnaryExpression::getFunction() const { +const std::shared_ptr &IUnaryExpression::getFunction() const noexcept { return func; } -const ArgumentPtrVector &IUnaryExpression::getChildren() const { +const ArgumentPtrVector &IUnaryExpression::getChildren() const noexcept { childrenCached.front() = child; return childrenCached; } diff --git a/src/fintamath/expressions/polynomial/MulExpr.cpp b/src/fintamath/expressions/polynomial/MulExpr.cpp index 3dedd03bc..a608113bf 100644 --- a/src/fintamath/expressions/polynomial/MulExpr.cpp +++ b/src/fintamath/expressions/polynomial/MulExpr.cpp @@ -35,7 +35,7 @@ MulExpr::MulExpr(ArgumentPtrVector inChildren) : IPolynomExpressionCRTP(Mul{}, std::move(inChildren)) { } -std::string MulExpr::toString() const { +std::string MulExpr::toString() const noexcept { auto [childNumerator, childDenominator] = splitRational(children.front()); if (*childDenominator != Integer(1)) { diff --git a/src/fintamath/expressions/polynomial/MulExpr.hpp b/src/fintamath/expressions/polynomial/MulExpr.hpp index f31aede8b..fcb0df5ea 100644 --- a/src/fintamath/expressions/polynomial/MulExpr.hpp +++ b/src/fintamath/expressions/polynomial/MulExpr.hpp @@ -14,7 +14,7 @@ class MulExpr final : public IPolynomExpressionCRTP { public: explicit MulExpr(ArgumentPtrVector inChildren); - std::string toString() const override; + std::string toString() const noexcept override; protected: std::string childToString(const IOperator &oper, const ArgumentPtr &inChild, const ArgumentPtr &prevChild) const override; diff --git a/src/fintamath/literals/Boolean.cpp b/src/fintamath/literals/Boolean.cpp index eef68b3d7..3e9dcade3 100644 --- a/src/fintamath/literals/Boolean.cpp +++ b/src/fintamath/literals/Boolean.cpp @@ -15,7 +15,7 @@ Boolean::Boolean(const std::string &str) { name = str; } -std::string Boolean::toString() const { +std::string Boolean::toString() const noexcept { return name; } diff --git a/src/fintamath/literals/Variable.cpp b/src/fintamath/literals/Variable.cpp index b4d46934a..1563a33eb 100644 --- a/src/fintamath/literals/Variable.cpp +++ b/src/fintamath/literals/Variable.cpp @@ -28,7 +28,7 @@ Variable::Variable(std::string inName, Integer inIndex) : Variable(std::move(inN index = std::move(inIndex); } -std::string Variable::toString() const { +std::string Variable::toString() const noexcept { return name + (index != -1 ? "_" + index.toString() : ""); } diff --git a/src/fintamath/numbers/Complex.cpp b/src/fintamath/numbers/Complex.cpp index 3c7829c4c..ec303e7e2 100644 --- a/src/fintamath/numbers/Complex.cpp +++ b/src/fintamath/numbers/Complex.cpp @@ -67,7 +67,7 @@ Complex::Complex(const Real &rhs) : re(cast(rhs.toMinimalObject())) { Complex::Complex(int64_t rhs) : re(std::make_unique(rhs)) { } -std::string Complex::toString() const { +std::string Complex::toString() const noexcept { std::string res; if (*re != Integer(0)) { @@ -107,7 +107,7 @@ std::string Complex::toString() const { return res; } -std::unique_ptr Complex::toMinimalObject() const { +std::unique_ptr Complex::toMinimalObject() const noexcept { if (*im == Integer(0)) { return re->toMinimalObject(); } @@ -131,7 +131,7 @@ const INumber &Complex::imag() const { return *im; } -bool Complex::equals(const Complex &rhs) const { +bool Complex::equals(const Complex &rhs) const noexcept { return *re == *rhs.re && *im == *rhs.im; } diff --git a/src/fintamath/numbers/Integer.cpp b/src/fintamath/numbers/Integer.cpp index 6caffe5bf..41dbc2ac0 100644 --- a/src/fintamath/numbers/Integer.cpp +++ b/src/fintamath/numbers/Integer.cpp @@ -35,7 +35,7 @@ Integer::Integer(std::string str) { Integer::Integer(const int64_t val) : backend(val) { } -std::string Integer::toString() const { +std::string Integer::toString() const noexcept { return backend.str(); } @@ -47,7 +47,7 @@ const Integer::Backend &Integer::getBackend() const { return backend; } -bool Integer::equals(const Integer &rhs) const { +bool Integer::equals(const Integer &rhs) const noexcept { return backend == rhs.backend; } diff --git a/src/fintamath/numbers/NumberAbstract.cpp b/src/fintamath/numbers/NumberAbstract.cpp index bb48f1413..8c044b035 100644 --- a/src/fintamath/numbers/NumberAbstract.cpp +++ b/src/fintamath/numbers/NumberAbstract.cpp @@ -55,7 +55,7 @@ std::unique_ptr Rational::divideAbstract(const IArithmetic &rhs) co //-------------------------------------------------------------------------------------// -bool Real::equalsAbstract(const IMathObject &rhs) const { +bool Real::equalsAbstract(const IMathObject &rhs) const noexcept { if (const auto *rhsNum = cast(&rhs); rhsNum && rhsNum->isPrecise()) { return false; } diff --git a/src/fintamath/numbers/Rational.cpp b/src/fintamath/numbers/Rational.cpp index 7d513a96a..3c95c04fe 100644 --- a/src/fintamath/numbers/Rational.cpp +++ b/src/fintamath/numbers/Rational.cpp @@ -85,7 +85,7 @@ const Integer &Rational::denominator() const { return denom; } -std::string Rational::toString() const { +std::string Rational::toString() const noexcept { std::string res = numer.toString(); if (denom != 1) { @@ -95,7 +95,7 @@ std::string Rational::toString() const { return res; } -std::unique_ptr Rational::toMinimalObject() const { +std::unique_ptr Rational::toMinimalObject() const noexcept { if (denom == 1) { return numer.clone(); } @@ -106,7 +106,7 @@ int Rational::sign() const { return numer.sign(); } -bool Rational::equals(const Rational &rhs) const { +bool Rational::equals(const Rational &rhs) const noexcept { return numer == rhs.numer && denom == rhs.denom; } diff --git a/src/fintamath/numbers/Real.cpp b/src/fintamath/numbers/Real.cpp index 165735ed3..fe6f28cb2 100644 --- a/src/fintamath/numbers/Real.cpp +++ b/src/fintamath/numbers/Real.cpp @@ -76,7 +76,7 @@ Real::Real(const int64_t val) : backend(val), isNegative(val < 0) { } -std::string Real::toString() const { +std::string Real::toString() const noexcept { std::string res = toString(outputPrecision); if (isNegative && res.front() != '-') { @@ -86,8 +86,8 @@ std::string Real::toString() const { return res; } -std::string Real::toString(unsigned precision) const { - validateNewPrecision(precision); +std::string Real::toString(unsigned precision) const noexcept { + assert(precision <= outputPrecision); if (precision == 0) { precision++; @@ -152,7 +152,7 @@ unsigned Real::getOutputPrecision() const { } void Real::setOutputPrecision(const unsigned precision) { - validateNewPrecision(precision); + assert(precision <= outputPrecision); outputPrecision = precision; } @@ -172,7 +172,7 @@ void Real::setPrecision(unsigned precision) { Backend::thread_default_precision(precision * precisionMultiplier + precisionDelta); } -bool Real::equals(const Real &rhs) const { +bool Real::equals(const Real &rhs) const noexcept { return backend == rhs.backend && isNegative == rhs.isNegative; } @@ -248,14 +248,6 @@ void Real::updatePrecision(const Real &rhs) { outputPrecision = std::min(outputPrecision, rhs.outputPrecision); } -void Real::validateNewPrecision(const unsigned precision) const { - if (precision > outputPrecision) { - // TODO: use std::format - throw InvalidInputException("Precision must be less than or equal to " + - std::to_string(outputPrecision)); - } -} - Real::ScopedSetPrecision::ScopedSetPrecision(const unsigned precision) { setPrecision(precision); } diff --git a/tests/src/expressions/FunctionExpressionTests.cpp b/tests/src/expressions/FunctionExpressionTests.cpp index b64ced571..bf459a625 100644 --- a/tests/src/expressions/FunctionExpressionTests.cpp +++ b/tests/src/expressions/FunctionExpressionTests.cpp @@ -13,7 +13,7 @@ class TestUnaryFunction final : public IFunctionCRTP { FINTAMATH_CLASS_BODY(TestExpression) public: - const std::shared_ptr &getFunction() const override { + const std::shared_ptr &getFunction() const noexcept override { static const std::shared_ptr func = cast(Add().clone()); return func; } - const ArgumentPtrVector &getChildren() const override { + const ArgumentPtrVector &getChildren() const noexcept override { static const ArgumentPtrVector children; return children; } diff --git a/tests/src/functions/calculus/DerivativeTests.cpp b/tests/src/functions/calculus/DerivativeTests.cpp index eb50a9f4b..ba1b1d65f 100644 --- a/tests/src/functions/calculus/DerivativeTests.cpp +++ b/tests/src/functions/calculus/DerivativeTests.cpp @@ -18,7 +18,7 @@ class TestComparable final : public IComparableCRTP { FINTAMATH_CLASS_BODY(TestComparable) public: - std::string toString() const override { + std::string toString() const noexcept override { return "testderivative"; } diff --git a/tests/src/numbers/RealTests.cpp b/tests/src/numbers/RealTests.cpp index c9acd2b07..c69e98c30 100644 --- a/tests/src/numbers/RealTests.cpp +++ b/tests/src/numbers/RealTests.cpp @@ -863,10 +863,6 @@ TEST(RealTests, toStringPrecisionPrecisionTest) { val = Real("10.1"); EXPECT_EQ(val.toString(0), "1.0*10"); - - Real::ScopedSetPrecision setPrecision(10); - val = Real("1.3"); - EXPECT_THROW(val.toString(20), InvalidInputException); } TEST(RealTests, getOutputPrecisionTest) { @@ -885,9 +881,6 @@ TEST(RealTests, setOutputPrecisionTest) { a.setOutputPrecision(5); EXPECT_EQ(a.getOutputPrecision(), 5); - - EXPECT_THROW(a.setOutputPrecision(6), InvalidInputException); - EXPECT_THROW(a.setOutputPrecision(10), InvalidInputException); } TEST(RealTests, updatePrecisionTest) { From 6a17545fbbc0247971b426663cc807f7f8efbb48 Mon Sep 17 00:00:00 2001 From: fintarin Date: Fri, 5 Apr 2024 22:56:23 +0400 Subject: [PATCH 3/3] Return set in IExpression::getVariables --- include/fintamath/core/MathObjectUtils.hpp | 10 +++++++++- include/fintamath/expressions/IExpression.hpp | 7 ++++++- src/fintamath/expressions/IExpression.cpp | 14 +++++--------- .../functions/ExpressionFunctionSolve.cpp | 4 ++-- tests/src/core/MathObjectUtilsTests.cpp | 4 ++++ tests/src/expressions/IExpressionTests.cpp | 9 ++++----- 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/include/fintamath/core/MathObjectUtils.hpp b/include/fintamath/core/MathObjectUtils.hpp index 50e8a2ee5..25220f558 100644 --- a/include/fintamath/core/MathObjectUtils.hpp +++ b/include/fintamath/core/MathObjectUtils.hpp @@ -136,4 +136,12 @@ std::shared_ptr cast(const std::shared_ptr &from) { return std::const_pointer_cast(cast(std::const_pointer_cast(from))); } -} \ No newline at end of file +template +struct ToStringComparator { + template + bool operator()(const T &lhs, const T &rhs) const noexcept { + return Comparator{}(lhs.toString(), rhs.toString()); + } +}; + +} diff --git a/include/fintamath/expressions/IExpression.hpp b/include/fintamath/expressions/IExpression.hpp index 7a02b3e1c..8004e91f3 100644 --- a/include/fintamath/expressions/IExpression.hpp +++ b/include/fintamath/expressions/IExpression.hpp @@ -2,12 +2,14 @@ #include #include +#include #include #include #include #include "fintamath/core/IMathObject.hpp" #include "fintamath/core/MathObjectClass.hpp" +#include "fintamath/core/MathObjectUtils.hpp" #include "fintamath/core/Parser.hpp" #include "fintamath/functions/FunctionArguments.hpp" #include "fintamath/functions/IFunction.hpp" @@ -20,6 +22,9 @@ namespace fintamath { class IExpression : public IMathObject { FINTAMATH_PARENT_CLASS_BODY(IExpression) +public: + using VariableSet = std::set>>; + public: virtual const std::shared_ptr &getFunction() const noexcept = 0; @@ -27,7 +32,7 @@ class IExpression : public IMathObject { virtual void setChildren(const ArgumentPtrVector &childVect) = 0; - std::vector getVariables() const; + VariableSet getVariables() const noexcept; virtual void setVariables(const std::vector> &varsToVals); diff --git a/src/fintamath/expressions/IExpression.cpp b/src/fintamath/expressions/IExpression.cpp index 2f2ded2df..58b591e14 100644 --- a/src/fintamath/expressions/IExpression.cpp +++ b/src/fintamath/expressions/IExpression.cpp @@ -28,23 +28,19 @@ using namespace detail; FINTAMATH_PARENT_CLASS_IMPLEMENTATION(IExpression) -std::vector IExpression::getVariables() const { - std::vector vars; +IExpression::VariableSet IExpression::getVariables() const noexcept { + VariableSet vars; for (const auto &child : getChildren()) { if (auto var = cast(child)) { - vars.emplace_back(*var); + vars.emplace(*var); } else if (const auto childExpr = cast(child)) { - std::vector childVars = childExpr->getVariables(); - vars.insert(vars.end(), childVars.begin(), childVars.end()); + VariableSet childVars = childExpr->getVariables(); + vars.insert(childVars.begin(), childVars.end()); } } - std::ranges::sort(vars, std::less{}, &Variable::toString); - auto unique = std::ranges::unique(vars); - vars.erase(unique.begin(), unique.end()); - return vars; } diff --git a/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp b/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp index 361b48f94..3ba64b2f1 100644 --- a/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp +++ b/src/fintamath/expressions/functions/ExpressionFunctionSolve.cpp @@ -44,7 +44,7 @@ Expression solve(const Expression &rhs) { // TODO: remove this if when inequalities will be implemented if (!is(compExpr->getFunction())) { - const auto var = cast(compExpr->getVariables().front()); + const auto var = cast(*compExpr->getVariables().begin()); const ArgumentPtrVector powerRate = getPolynomCoefficients(compExpr->getChildren().front(), var); if (powerRate.size() == 2) { @@ -55,7 +55,7 @@ Expression solve(const Expression &rhs) { return rhs; } - const auto var = cast(compExpr->getVariables().front()); + const auto var = cast(*compExpr->getVariables().begin()); const ArgumentPtrVector powerRates = getPolynomCoefficients(compExpr->getChildren().front(), var); ArgumentPtrVector roots; diff --git a/tests/src/core/MathObjectUtilsTests.cpp b/tests/src/core/MathObjectUtilsTests.cpp index bc4b6223f..21336e596 100644 --- a/tests/src/core/MathObjectUtilsTests.cpp +++ b/tests/src/core/MathObjectUtilsTests.cpp @@ -57,3 +57,7 @@ TEST(MathObjectUtilsTests, castTest) { EXPECT_TRUE(cast(std::const_pointer_cast(std::shared_ptr(i.clone())))); EXPECT_FALSE(cast(std::const_pointer_cast(std::shared_ptr(E().clone())))); } + +TEST(MathObjectUtilsTests, compareByToStringTest) { + // TODO: implement +} diff --git a/tests/src/expressions/IExpressionTests.cpp b/tests/src/expressions/IExpressionTests.cpp index 7d958ff44..125f58f20 100644 --- a/tests/src/expressions/IExpressionTests.cpp +++ b/tests/src/expressions/IExpressionTests.cpp @@ -1,8 +1,10 @@ +#include #include #include "fintamath/expressions/IExpression.hpp" #include "fintamath/expressions/Expression.hpp" +#include "fintamath/expressions/ExpressionParser.hpp" #include "fintamath/expressions/ExpressionUtils.hpp" #include "fintamath/functions/arithmetic/Add.hpp" #include "fintamath/functions/other/Factorial.hpp" @@ -82,11 +84,8 @@ TEST(IExpressionTests, setChildrenTest) { } TEST(IExpressionTests, getVariablesTest) { - const auto expr = cast(Expression("x^2+y^2+a").clone()); - const auto vars = expr->getVariables(); - EXPECT_EQ(vars[0].toString(), "a"); - EXPECT_EQ(vars[1].toString(), "x"); - EXPECT_EQ(vars[2].toString(), "y"); + const auto expr = cast(parseExpr("x^2+y^2+a")); + EXPECT_THAT(expr->getVariables(), testing::ElementsAre(Variable("a"), Variable("x"), Variable("y"))); // TODO: implement more tests }