diff --git a/src/openvic-simulation/core/template/Concepts.hpp b/src/openvic-simulation/core/template/Concepts.hpp index 3f1209a2..3063bfb9 100644 --- a/src/openvic-simulation/core/template/Concepts.hpp +++ b/src/openvic-simulation/core/template/Concepts.hpp @@ -142,6 +142,9 @@ namespace OpenVic { { typename Case::equal {}(identifier, identifier) } -> std::same_as; }; + template + concept integral_max_size_4 = std::integral && sizeof(T) <= 4; + template concept unary_negatable = requires(T const& a) { { -a } -> std::same_as; diff --git a/src/openvic-simulation/types/fixed_point/FixedPoint.hpp b/src/openvic-simulation/types/fixed_point/FixedPoint.hpp index cd92fd6a..cdcdb1f3 100644 --- a/src/openvic-simulation/types/fixed_point/FixedPoint.hpp +++ b/src/openvic-simulation/types/fixed_point/FixedPoint.hpp @@ -22,6 +22,7 @@ #include "openvic-simulation/utility/Containers.hpp" #include "openvic-simulation/core/Typedefs.hpp" #include "openvic-simulation/core/Math.hpp" +#include "openvic-simulation/core/template/Concepts.hpp" /* Sin lookup table */ #include "openvic-simulation/types/fixed_point/FixedPointLUT_sin.hpp" @@ -107,39 +108,39 @@ namespace OpenVic { static const fixed_point_t e; // Standard for constexpr requires this here - template + template OV_SPEED_INLINE constexpr friend fixed_point_t operator/(fixed_point_t const& lhs, T const& rhs) { return parse_raw(lhs.value / rhs); } - template + template OV_SPEED_INLINE constexpr friend fixed_point_t operator/(T const& lhs, fixed_point_t const& rhs) { return parse_raw((static_cast(lhs) << (2 * PRECISION)) / rhs.value); } - template + template OV_SPEED_INLINE constexpr fixed_point_t& operator/=(T const& obj) { value /= obj; return *this; } - template + template OV_SPEED_INLINE constexpr friend fixed_point_t operator*(fixed_point_t const& lhs, T const& rhs) { return parse_raw(lhs.value * rhs); } - template + template OV_SPEED_INLINE constexpr fixed_point_t& operator*=(T const& obj) { value *= obj; return *this; } - template + template OV_SPEED_INLINE constexpr friend fixed_point_t operator+(fixed_point_t const& lhs, T const& rhs) { return parse_raw(lhs.value + (static_cast(rhs) << PRECISION)); } - template + template OV_SPEED_INLINE constexpr std::strong_ordering operator<=>(T const& rhs) const { return value <=> static_cast(rhs) << PRECISION; } @@ -525,7 +526,7 @@ namespace OpenVic { return parse_raw(lhs.value + rhs.value); } - template + template OV_SPEED_INLINE constexpr friend fixed_point_t operator+(T const& lhs, fixed_point_t const& rhs) { return parse_raw((static_cast(lhs) << PRECISION) + rhs.value); } @@ -535,7 +536,7 @@ namespace OpenVic { return *this; } - template + template OV_SPEED_INLINE constexpr fixed_point_t& operator+=(T const& obj) { value += (static_cast(obj) << PRECISION); return *this; @@ -545,12 +546,12 @@ namespace OpenVic { return parse_raw(lhs.value - rhs.value); } - template + template OV_SPEED_INLINE constexpr friend fixed_point_t operator-(fixed_point_t const& lhs, T const& rhs) { return parse_raw(lhs.value - (static_cast(rhs) << PRECISION)); } - template + template OV_SPEED_INLINE constexpr friend fixed_point_t operator-(T const& lhs, fixed_point_t const& rhs) { return parse_raw((static_cast(lhs) << PRECISION) - rhs.value); } @@ -560,7 +561,7 @@ namespace OpenVic { return *this; } - template + template OV_SPEED_INLINE constexpr fixed_point_t& operator-=(T const& obj) { value -= (static_cast(obj) << PRECISION); return *this; @@ -588,12 +589,12 @@ namespace OpenVic { return old; } - template + template OV_SPEED_INLINE constexpr friend fixed_point_t operator<<(fixed_point_t const& lhs, T const& rhs) { return parse_raw(lhs.value << rhs); } - template + template OV_SPEED_INLINE constexpr friend fixed_point_t operator>>(fixed_point_t const& lhs, T const& rhs) { return parse_raw(lhs.value >> rhs); } @@ -602,7 +603,7 @@ namespace OpenVic { return parse_raw(lhs.value * rhs.value >> PRECISION); } - template + template OV_SPEED_INLINE constexpr friend fixed_point_t operator*(T const& lhs, fixed_point_t const& rhs) { return parse_raw(lhs * rhs.value); } @@ -631,12 +632,12 @@ namespace OpenVic { return parse_raw(lhs.value % rhs.value); } - template + template OV_SPEED_INLINE constexpr friend fixed_point_t operator%(fixed_point_t const& lhs, T const& rhs) { return parse_raw(lhs.value % (static_cast(rhs) << PRECISION)); } - template + template OV_SPEED_INLINE constexpr friend fixed_point_t operator%(T const& lhs, fixed_point_t const& rhs) { return parse_raw((static_cast(lhs) << PRECISION) % rhs.value); } @@ -646,7 +647,7 @@ namespace OpenVic { return *this; } - template + template OV_SPEED_INLINE constexpr fixed_point_t& operator%=(T const& obj) { value %= (static_cast(obj) << PRECISION); return *this; @@ -656,7 +657,7 @@ namespace OpenVic { return lhs.value == rhs.value; } - template + template OV_SPEED_INLINE constexpr bool operator==(T const& rhs) const { return value == static_cast(rhs) << PRECISION; }