diff options
author | zaaarf <80046572+zaaarf@users.noreply.github.com> | 2024-01-02 15:48:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-02 15:48:56 +0100 |
commit | 791e64795a5f688e5ae673b88c5f2787d6450ce8 (patch) | |
tree | cf9324311fb1b49a09ccc17dc8f2ba4d24fae538 /src/openvic-simulation/types | |
parent | 4c8da86c3bede8834f381fa63edaa3e140131f69 (diff) | |
parent | 2f5706fd5ef6bbdee54c82860e03f00a96751693 (diff) |
Merge pull request #114 from OpenVicProject/squared-roots
Integer and fixed point squared roots
Diffstat (limited to 'src/openvic-simulation/types')
-rw-r--r-- | src/openvic-simulation/types/fixed_point/FixedPoint.hpp | 6 |
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); |