diff --git a/include/Nazara/Math/Algorithm.hpp b/include/Nazara/Math/Algorithm.hpp index 7c22947b9..5109c68d5 100644 --- a/include/Nazara/Math/Algorithm.hpp +++ b/include/Nazara/Math/Algorithm.hpp @@ -61,7 +61,9 @@ namespace Nz template constexpr bool NumberEquals(T a, T b, T maxDifference); inline std::string NumberToString(long long number, UInt8 radix = 10); template constexpr T RadianToDegree(T radians); + template T SetBit(T number, T bit); inline long long StringToNumber(const std::string_view& str, UInt8 radix = 10, bool* ok = nullptr); + template bool TestBit(T number, T bit); template constexpr T ToDegrees(T angle); template constexpr T ToRadians(T angle); } diff --git a/include/Nazara/Math/Algorithm.inl b/include/Nazara/Math/Algorithm.inl index d480f60f8..f5ef47381 100644 --- a/include/Nazara/Math/Algorithm.inl +++ b/include/Nazara/Math/Algorithm.inl @@ -624,6 +624,13 @@ namespace Nz return radians * T(180.0/M_PI); } + template + T SetBit(T number, T bit) + { + NazaraAssert(bit < sizeof(number)* CHAR_BIT, "bit index out of range"); + return number |= (T(1) << bit); + } + /*! * \ingroup math * \brief Converts the string to number @@ -689,6 +696,13 @@ namespace Nz return (negative) ? -static_cast(total) : total; } + template + bool TestBit(T number, T bit) + { + NazaraAssert(bit < sizeof(number) * CHAR_BIT, "bit index out of range"); + return number & (T(1) << bit); + } + /*! * \ingroup math * \brief Gets the degree from unit and convert it according to NAZARA_MATH_ANGLE_RADIAN