// Copyright (C) 2026 Kiyotsugu Arai // SPDX-License-Identifier: LGPL-3.0-or-later // RationalConstants.hpp // Rational-valued constants: Bernoulli numbers, Stirling coefficients // #ifndef SANGI_RATIONAL_CONSTANTS_HPP #define SANGI_RATIONAL_CONSTANTS_HPP #include namespace sangi { /** * @brief Compute the Bernoulli number B(n) * * Standard recurrence: B(n) = -1/(n+1) * sum C(n+1,k) * B(k). * B(0) = 1, B(1) = -1/2, B(odd > 1) = 0. * Previously computed values are kept in a static cache (thread-safe). * * @param n index of the Bernoulli number (n >= 0) * @return B(n) as a Rational */ [[nodiscard]] Rational bernoulli(int n); /** * @brief Compute the Stirling coefficient c[k] * * Coefficient in Stirling's approximation * n! ~ sqrt(2*pi*n) * (n/e)^n * (1 + c[1]/n + c[2]/n^2 + ...). * c[0] = 1. Computed via a recurrence involving Bernoulli numbers. * Previously computed values are kept in a static cache (thread-safe). * * Sources: * "Concerning Two Series for the Gamma Function" p618 * "A New Derivation of Stirling's Approximation to n!" p828 * * @param k coefficient index (k >= 0) * @return c[k] as a Rational */ [[nodiscard]] Rational stirlingCoefficient(int k); } // namespace sangi #endif // SANGI_RATIONAL_CONSTANTS_HPP