diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-09-02 08:12:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-02 08:12:34 +0200 |
| commit | 0973d92a0bcec317c621ff90ae296b862db6409f (patch) | |
| tree | 86dbd0e0d12162dfebafbd8a4086f1d297b05bdb /dev/LibC++/base_math.h | |
| parent | 891bc2653b911a4553a39d03bae4d62d866dbd07 (diff) | |
| parent | d84a951e42b69a1c2665548fa5d5f621b91e51ec (diff) | |
Merge pull request #11 from nekernel-org/dev
v0.0.1e3 — Langley
Diffstat (limited to 'dev/LibC++/base_math.h')
| -rw-r--r-- | dev/LibC++/base_math.h | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/dev/LibC++/base_math.h b/dev/LibC++/base_math.h index ca6aace..7c9f34d 100644 --- a/dev/LibC++/base_math.h +++ b/dev/LibC++/base_math.h @@ -18,6 +18,8 @@ typedef float real_type; #endif namespace std::base_math { +inline constexpr static auto not_a_number = NAN; + /// @brief Power function, with Repeat argument. template <size_t Exponent> inline real_type pow(real_type in) { @@ -34,13 +36,32 @@ inline real_type pow(real_type in) { return result; } +inline real_type sqrt(real_type in) { + if (in == 0) return 0; + if (in == not_a_number) return not_a_number; + + auto constexpr const static Base = 2; + + auto x = in / Base; + + for (int i = 0; i < 10; ++i) { + x = (x + in / x) / Base; + } + + return x; +} + /// @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) { +inline real_type surd(real_type in) { if (in == 0) return 0; + if (in == 1) return 1; + + if (Base == 1) return in; + if (Base == 2) return sqrt(in); - return pow<1 / Base>(in); + return not_a_number; } /// @brief Linear interpolation equation solver. |
