Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
utils.hpp File Reference

Integer powers with a supplied reciprocal, so a negative exponent never divides. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  shamunits
 namespace containing the units library

Functions

template<int power, class T>
constexpr T shamunits::details::pow_constexpr_fast_inv (T a, T a_inv) noexcept
 Constexpr power expansion function with supplied inverse for negative values.
template<class T>
constexpr T shamunits::details::ipow (T a, int n, T a_inv) noexcept
 Runtime twin of pow_constexpr_fast_inv, for an exponent only known at run time.

Detailed Description

Integer powers with a supplied reciprocal, so a negative exponent never divides.

Author
Timothée David–Cléris (tim.s.nosp@m.hamr.nosp@m.ock@p.nosp@m.roto.nosp@m.n.me)

Definition in file utils.hpp.

Function Documentation

◆ ipow()

template<class T>
T shamunits::details::ipow ( T a,
int n,
T a_inv )
inlineconstexprnoexcept

Runtime twin of pow_constexpr_fast_inv, for an exponent only known at run time.

Same square-and-multiply order (most significant bit first), so for any n it returns exactly what pow_constexpr_fast_inv<n> returns. The caller supplies the reciprocal, so a negative exponent uses a_inv and never divides.

Definition at line 45 of file utils.hpp.

◆ pow_constexpr_fast_inv()

template<int power, class T>
T shamunits::details::pow_constexpr_fast_inv ( T a,
T a_inv )
inlineconstexprnoexcept

Constexpr power expansion function with supplied inverse for negative values.

Definition at line 22 of file utils.hpp.