36 template <std::
integral T_Type>
37 [[nodiscard]] constexpr
auto is_power_of_2(T_Type value) noexcept -> bool;
51 template <std::
integral T_Type>
68 template <Number T_Type>
69 [[nodiscard]] constexpr
auto power(T_Type base, std::integral
auto exponent) noexcept -> T_Type;
86 template <Number T_Type = UST>
87 [[nodiscard]] constexpr
auto power_of_2(std::integral
auto exponent) noexcept -> T_Type;
102 template <std::
integral T_Type>
106 return (value > 0) && ! (u_value & (u_value - 1));
112 template <std::
integral T_Type>
115 assert(n >= 0 &&
"n must be a positive number");
117 return (n * n + n) / 2;
123 template <Number T_Type>
125 [[nodiscard]] constexpr
auto power(T_Type base, std::integral
auto exponent) noexcept -> T_Type
127 assert(exponent >= 0 &&
"exponent must be a positive number");
131 if (exponent % 2 == 0)
132 return power(base, exponent / 2) *
power(base, exponent / 2);
133 return base *
power(base, (exponent - 1) / 2) *
power(base, (exponent - 1) / 2);
139 template <Number T_Type>
140 [[nodiscard]] constexpr
auto power_of_2(std::integral
auto exponent) noexcept -> T_Type
142 assert(exponent >= 0 &&
"exponent must be a positive number");
144 return static_cast<T_Type
>(
UST(1) <<
static_cast<UST>(exponent));
Contains some basic definitions and concepts that are frequently needed.
Defines the fundamental data types.
std::size_t UST
Unsigned integer type that is returned by sizeof operations.
Definition: fundamental_types.h:29
constexpr auto is_power_of_2(T_Type value) noexcept -> bool
Return true if the passed value is a power of 2.
Definition: math.h:103
constexpr auto power(T_Type base, std::integral auto exponent) noexcept -> T_Type
Calculate the power of a number using an integer based exponent.
Definition: math.h:125
constexpr auto gauss_summation(T_Type n) -> T_Type
Calculate the sum of the first n positive numbers.
Definition: math.h:113
constexpr auto power_of_2(std::integral auto exponent) noexcept -> T_Type
Calculate the power of 2 using an integer based exponent.
Definition: math.h:140
constexpr auto signed_to_unsigned(T_Type value) -> EquallySizedUnsignedType< T_Type >
Cast an integer to an equally sized unsigned type.
Definition: type.h:94
Contains multiple utility functions for type related operations.