diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-10-21 20:24:25 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-10-21 20:24:25 +0200 |
| commit | 662860f03cdff8ea18b691dca1f3c84a4aaf07d5 (patch) | |
| tree | b3869c84e6a146ff183e0e201ab7160ce5d2a9a6 /dev/LibC++/math.h | |
| parent | 32312160ea0c1fc2fd1e893721260de44dfdd78c (diff) | |
IMP: Major refactor of header and source files extensions.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/LibC++/math.h')
| -rw-r--r-- | dev/LibC++/math.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/dev/LibC++/math.h b/dev/LibC++/math.h new file mode 100644 index 0000000..b6cd6a8 --- /dev/null +++ b/dev/LibC++/math.h @@ -0,0 +1,62 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include <LibC++/defines.hxx> + +/// @file Math.hxx +/// @brief Math functions. + +#ifdef __ZKA_USE_DOUBLE__ +typedef double real_type; +#else +typedef float real_type; +#endif + +namespace std::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::math |
