1#ifndef _BBM_FACTORIAL_H_
2#define _BBM_FACTORIAL_H_
21 template<
typename T>
requires std::integral<T>
22 constexpr T max_int(
void)
24 return std::numeric_limits<T>::max();
27 template<
typename T>
requires std::floating_point<T>
28 constexpr T max_int(
void)
30 return (1ull << (std::numeric_limits<T>::digits));
42 template<
typename T=
unsigned long long int>
requires std::integral<T> || std::floating_point<T>
46 T fac = bbm::detail::max_int<T>();
47 while(fac > n) fac /= n++;
53 namespace precomputed {
55 static constexpr auto factorials = []<
size_t... N>(std::index_sequence<N...>)
57 unsigned long long int acc=1;
58 return std::array<unsigned long long int, max_factorial<unsigned long long int>()+2>{ 1, (acc*=(N+1))...};
59 }(std::make_index_sequence<max_factorial<unsigned long long int>()+1>{});
72 template<
typename T=
unsigned long long int>
Predefined exceptions for common errors.
#define bbm_out_of_range
Definition: error.h:44
static constexpr auto factorials
Definition: factorial.h:55
Definition: aggregatebsdf.h:29
consteval size_t max_factorial(void)
Returns the largest possible factorial index for a given type that does not result in an overflow.
Definition: factorial.h:43
constexpr T factorial(size_t n)
Compute n!
Definition: factorial.h:73