Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
18namespace shamunits::details {
19
21 template<int power, class T>
22 inline constexpr T pow_constexpr_fast_inv(T a, T a_inv) noexcept {
23
24 if constexpr (power < 0) {
25 return pow_constexpr_fast_inv<-power>(a_inv, a);
26 } else if constexpr (power == 0) {
27 return T{1};
28 } else if constexpr (power % 2 == 0) {
29 T tmp = pow_constexpr_fast_inv<power / 2>(a, a_inv);
30 return tmp * tmp;
31 } else if constexpr (power % 2 == 1) {
32 T tmp = pow_constexpr_fast_inv<(power - 1) / 2>(a, a_inv);
33 return tmp * tmp * a;
34 }
35 }
36} // namespace shamunits::details