Template helper functions updated
ABS, NEGATE AND POW now accept floating point types along with integral types
This commit is contained in:

committed by
GitHub

parent
c915e103a8
commit
814eb04649
@ -39,21 +39,21 @@ namespace JRAMPERSAD
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
[[nodiscard("MATH::ABS(T) returns a value of type T")]] T ABS(const T& n) noexcept
|
[[nodiscard("MATH::ABS(T) returns a value of type T")]] T ABS(const T& n) noexcept
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral<T>::value, "Integral required.");
|
static_assert(std::is_arithmetic<T>::value, "Arithmetic type required.");
|
||||||
return n < 0 ? n * -1 : n;
|
return n < 0 ? n * -1 : n;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
[[nodiscard("MATH::NEGATE(T) returns a value of type T")]] T NEGATE(const T& n) noexcept
|
[[nodiscard("MATH::NEGATE(T) returns a value of type T")]] T NEGATE(const T& n) noexcept
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral<T>::value, "Integral required.");
|
static_assert(std::is_arithmetic<T>::value, "Arithmetic type required.");
|
||||||
return n * -1;
|
return n * -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
[[nodiscard("MATH::POW(T, int) returns a value of type T")]] T POW(const T& n, const int& exp) noexcept
|
[[nodiscard("MATH::POW(T, int) returns a value of type T")]] T POW(const T& n, const int& exp) noexcept
|
||||||
{
|
{
|
||||||
static_assert(std::is_integral<T>::value, "Integral required.");
|
static_assert(std::is_arithmetic<T>::value, "Arithmetic type required.");
|
||||||
if (exp == 0)
|
if (exp == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user