diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-25 13:14:01 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-25 13:14:01 +0200 |
| commit | 20042235d1f53ae428aa154e64afdbae5d8d91ad (patch) | |
| tree | 6ea42d1b30505a57301f8ff2916c78ce94ff6eaf /dev/LibC++/base_math.h | |
| parent | 0561a8d0a6ae7588309a6e3513bbfeeef5f0aa15 (diff) | |
meta: update .clang-format, format codebase.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/LibC++/base_math.h')
| -rw-r--r-- | dev/LibC++/base_math.h | 80 |
1 files changed, 36 insertions, 44 deletions
diff --git a/dev/LibC++/base_math.h b/dev/LibC++/base_math.h index ed1728e..ca6aace 100644 --- a/dev/LibC++/base_math.h +++ b/dev/LibC++/base_math.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -17,46 +17,38 @@ typedef double real_type; typedef float real_type; #endif -namespace std::base_math -{ - /// @brief Power function, with Repeat argument. - template <size_t Exponent> - inline real_type pow(real_type in) - { - if (Exponent == 0) - return 1; // Any number to the power of 0 is 1. - - if (Exponent == 1) - return in; // Any number to the power of 1 is itself. - - size_t cnt = Exponent; - - real_type result = 1; - - for (auto i = 0; i < cnt; ++i) - result *= in; - - return result; - } - - /// @brief Square of function, with Base template argument. - /// @param of Base argument to find sqquare of - template <size_t Base> - inline real_type sqr(real_type in) - { - if (in == 0) - return 0; - - return pow<1 / Base>(in); - } - - /// @brief Linear interpolation equation solver. - /// @param from where? - /// @param to to? - /// @param Updated diff value according to difference. - inline real_type lerp(real_type to, real_type from, real_type stat) - { - real_type diff = (to - from); - return from + (diff * stat); - } -} // namespace std::base_math +namespace std::base_math { +/// @brief Power function, with Repeat argument. +template <size_t Exponent> +inline real_type pow(real_type in) { + if (Exponent == 0) return 1; // Any number to the power of 0 is 1. + + if (Exponent == 1) return in; // Any number to the power of 1 is itself. + + size_t cnt = Exponent; + + real_type result = 1; + + for (auto i = 0; i < cnt; ++i) result *= in; + + return result; +} + +/// @brief Square of function, with Base template argument. +/// @param of Base argument to find sqquare of +template <size_t Base> +inline real_type sqr(real_type in) { + if (in == 0) return 0; + + return pow<1 / Base>(in); +} + +/// @brief Linear interpolation equation solver. +/// @param from where? +/// @param to to? +/// @param Updated diff value according to difference. +inline real_type lerp(real_type to, real_type from, real_type stat) { + real_type diff = (to - from); + return from + (diff * stat); +} +} // namespace std::base_math |
