WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
beta.hpp
Go to the documentation of this file.
1/*################################################################################
2 ##
3 ## Copyright (C) 2016-2024 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21#ifndef _gcem_beta_HPP
22#define _gcem_beta_HPP
23
24#include <cmath>
25#include <type_traits>
26
27namespace gcem
28{
29
30/**
31 * Compile-time beta function
32 *
33 * @param a a real-valued input.
34 * @param b a real-valued input.
35 * @return the beta function using \f[ \text{B}(\alpha,\beta) := \int_0^1 t^{\alpha - 1} (1-t)^{\beta - 1} dt = \frac{\Gamma(\alpha)\Gamma(\beta)}{\Gamma(\alpha + \beta)} \f]
36 * where \f$ \Gamma \f$ denotes the gamma function.
37 */
38
39template<typename T1, typename T2>
40constexpr
42beta(const T1 a, const T2 b)
43noexcept
44{
45 if (std::is_constant_evaluated()) {
46 return exp( lbeta(a,b) );
47 } else {
48#ifdef __cpp_lib_math_special_functions
49 return std::beta(a, b);
50#else
51 return exp( lbeta(a,b) );
52#endif
53 }
54}
55
56}
57
58#endif
Definition is_odd.hpp:29
constexpr common_return_t< T1, T2 > beta(const T1 a, const T2 b) noexcept
Compile-time beta function.
Definition beta.hpp:42
return_t< common_t< T... > > common_return_t
Definition gcem_options.hpp:83
constexpr common_return_t< T1, T2 > lbeta(const T1 a, const T2 b) noexcept
Compile-time log-beta function.
Definition lbeta.hpp:39