aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/types
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/types')
-rw-r--r--src/openvic-simulation/types/fixed_point/FixedPoint.hpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/openvic-simulation/types/fixed_point/FixedPoint.hpp b/src/openvic-simulation/types/fixed_point/FixedPoint.hpp
index 75abefb..8d3a74b 100644
--- a/src/openvic-simulation/types/fixed_point/FixedPoint.hpp
+++ b/src/openvic-simulation/types/fixed_point/FixedPoint.hpp
@@ -209,6 +209,12 @@ namespace OpenVic {
return !is_negative() ? value : -value;
}
+ constexpr fixed_point_t sqrt() const {
+ return !is_negative()
+ ? static_cast<int64_t>(NumberUtils::sqrt(static_cast<uint64_t>(value) << PRECISION))
+ : 0;
+ }
+
// Doesn't account for sign, so -n.abc -> 1 - 0.abc
constexpr fixed_point_t get_frac() const {
return value & (ONE - 1);