summaryrefslogtreecommitdiffhomepage
path: root/dev/LibC++/base_math.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-08-28 13:47:46 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-08-28 13:47:46 +0200
commit7258392baba60c0f4d71ff62ca4e50015cd22ae4 (patch)
tree7064b539b2beccf2c5e338dec8313fa7a2e065de /dev/LibC++/base_math.h
parentca34109b59c92df1698c69455cab59ad0d105aab (diff)
hotpatch: fix `surd` function.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/LibC++/base_math.h')
-rw-r--r--dev/LibC++/base_math.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/dev/LibC++/base_math.h b/dev/LibC++/base_math.h
index 94c34e8..220d357 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) {
@@ -39,8 +41,14 @@ inline real_type pow(real_type in) {
template <size_t Base>
inline real_type surd(real_type in) {
if (in == 0) return 0;
+ if (in == 1) return 1;
+ if (Base == 1) return in;
+
+ auto x = in / Base;
+
+ if (Base == 2) return (x + in / x) / 2;
- return pow<1 / Base>(in);
+ return not_a_number;
}
/// @brief Linear interpolation equation solver.