From f40d09cb8f712e87691af4912f3630d92d692779 Mon Sep 17 00:00:00 2001 From: untodesu Date: Thu, 11 Dec 2025 15:14:26 +0500 Subject: Shuffle stuff around - Use the new and improved hierarchy I figured out when making Prospero chat - Re-add NSIS scripts, again from Prospero - Update most build and utility scripts with their most recent versions --- src/core/math/constexpr.hh | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/core/math/constexpr.hh (limited to 'src/core/math/constexpr.hh') diff --git a/src/core/math/constexpr.hh b/src/core/math/constexpr.hh new file mode 100644 index 0000000..4158803 --- /dev/null +++ b/src/core/math/constexpr.hh @@ -0,0 +1,72 @@ +#pragma once + +#include "core/math/concepts.hh" + +namespace math +{ +template +constexpr std::size_t array_size(const type (&)[size]); +} // namespace math + +namespace math +{ +template +constexpr scalar log2(const scalar x); +template +constexpr scalar mod_signed(const scalar x, const scalar m); +template +constexpr result_scalar sign(const scalar x); +} // namespace math + +namespace math +{ +template +constexpr scalar degrees(const scalar x); +template +constexpr scalar radians(const scalar x); +} // namespace math + +template +constexpr std::size_t math::array_size(const type (&)[size]) +{ + return size; +} + +template +constexpr scalar math::log2(const scalar x) +{ + if(x < static_cast(2)) + return static_cast(0); + return math::log2((x + static_cast(1)) >> 1) + static_cast(1); +} + +template +constexpr scalar math::mod_signed(const scalar x, const scalar m) +{ + auto result = static_cast(x % m); + if(result < static_cast(0)) + return result + m; + return result; +} + +template +constexpr result_scalar math::sign(const scalar x) +{ + if(x < static_cast(0)) + return static_cast(-1); + if(x > static_cast(0)) + return static_cast(+1); + return static_cast(0); +} + +template +constexpr scalar math::degrees(const scalar x) +{ + return static_cast(static_cast(x) * 180.0 / M_PI); +} + +template +constexpr scalar math::radians(const scalar x) +{ + return static_cast(static_cast(x) * M_PI / 180.0); +} -- cgit