Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
floats.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
20
21namespace shambase {
22
23 template<i32 power, class T>
24 inline constexpr T pow_constexpr_fast_inv(T a, T a_inv) noexcept {
25
26 if constexpr (power < 0) {
27 return pow_constexpr_fast_inv<-power>(a_inv, a);
28 } else if constexpr (power == 0) {
29 return T{1};
30 } else if constexpr (power % 2 == 0) {
31 T tmp = pow_constexpr_fast_inv<power / 2>(a, a_inv);
32 return tmp * tmp;
33 } else if constexpr (power % 2 == 1) {
34 T tmp = pow_constexpr_fast_inv<(power - 1) / 2>(a, a_inv);
35 return tmp * tmp * a;
36 }
37 }
38
39} // namespace shambase
namespace for basic c++ utilities
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.