diff --git a/include/Ishiko/Math/Numbers/FixedPointNumber.hpp b/include/Ishiko/Math/Numbers/FixedPointNumber.hpp index 3c0ffe1..799642f 100644 --- a/include/Ishiko/Math/Numbers/FixedPointNumber.hpp +++ b/include/Ishiko/Math/Numbers/FixedPointNumber.hpp @@ -9,7 +9,51 @@ namespace Ishiko template class FixedPointNumber { + static_assert(scale <= precision, "Scale cannot exceed precision"); + + public: + FixedPointNumber() noexcept; + explicit FixedPointNumber(int value); + + bool operator==(const FixedPointNumber& other) const noexcept; + bool operator!=(const FixedPointNumber& other) const noexcept; + + private: + // Helper to select appropriate integer type based on precision + using storage_type = + std::conditional_t< + (precision <= std::numeric_limits::digits10), + int32_t, + std::conditional_t<(precision <= std::numeric_limits::digits10), int64_t, void> + >; + static_assert(!std::is_void::value, "Precision exceeds maximum supported value (18 digits)"); + + storage_type m_value; }; } +template +Ishiko::FixedPointNumber::FixedPointNumber() noexcept + : m_value(0) +{ +} + +template +Ishiko::FixedPointNumber::FixedPointNumber(int value) + : m_value(value) +{ +} + +template +bool Ishiko::FixedPointNumber::operator==(const FixedPointNumber& other) const noexcept +{ + return m_value == other.m_value; +} + +template +bool Ishiko::FixedPointNumber::operator!=(const FixedPointNumber& other) const noexcept +{ + return m_value != other.m_value; +} + #endif diff --git a/numbers/tests/src/FixedPointNumberTests.cpp b/numbers/tests/src/FixedPointNumberTests.cpp index 89c4331..bc3a61c 100644 --- a/numbers/tests/src/FixedPointNumberTests.cpp +++ b/numbers/tests/src/FixedPointNumberTests.cpp @@ -16,5 +16,6 @@ void FixedPointNumberTests::ConstructorTest1(Test& test) { FixedPointNumber<10, 2> fixed_point_number; + ISHIKO_TEST_FAIL_IF_NEQ(fixed_point_number, (FixedPointNumber<10, 2>(0))); ISHIKO_TEST_PASS(); }