Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
native_gamma_math.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "native_math.hpp"
5
6namespace uni20::detail::native_math
7{
8// Stirling log-Gamma correction at x=1/inverse. Callers use x>=8 for
9// float32, x>=16 for binary64/80 and x>=32 for binary128; the coefficient
10// generator records the first omitted term at those thresholds.
11template <NativeReal R> R stirling_correction(R inverse)
12{
13 constexpr int bits = numeric_limits<R>::digits();
14 constexpr int terms = bits <= 24 ? 4 : bits <= 53 ? 8 : bits <= 64 ? 10 : 16;
15 constexpr auto coefficients = uni20::detail::native_stirling_coefficients<R>();
16 R square = inverse * inverse, result = coefficients[terms - 1];
17 for (int k = terms - 2; k >= 0; --k)
18 result = std::fma(result, square, coefficients[k]);
19 return inverse * result;
20}
21} // namespace uni20::detail::native_math
AsyncTask square(ReadBuffer< int > in, WriteBuffer< int > out)
Definition async_tbb_reduction_example.cpp:39