numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
gamma.h
Go to the documentation of this file.
1/*
2 * Copyright 2024 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <cmath>
23#include <complex>
24
28
35[[nodiscard]] constexpr auto gamma(float x) -> float {
36 if (x < 1.0F) {
37 const float pi_1mx = constants::pi<float> * (1.0F - x);
38 return pi_1mx / std::sin(pi_1mx) /
39 // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
41 }
43}
44
51[[nodiscard]] constexpr auto gamma(double x) -> double {
52 if (x < 1.0) {
53 const double pi_1mx = constants::pi<double> * (1.0 - x);
54 return pi_1mx / std::sin(pi_1mx) /
55 // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
57 }
59}
60
67[[nodiscard]] constexpr auto gamma(std::complex<float> x)
68 -> std::complex<float> {
69 if (x.real() < 1.0F) {
70 const std::complex<float> pi_1mx = constants::pi<float> * (1.0F - x);
71 return pi_1mx / std::sin(pi_1mx) /
72 // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
74 }
76}
77
84[[nodiscard]] constexpr auto gamma(std::complex<double> x)
85 -> std::complex<double> {
86 if (x.real() < 1.0) {
87 const std::complex<double> pi_1mx = constants::pi<double> * (1.0 - x);
88 return pi_1mx / std::sin(pi_1mx) /
89 // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
91 }
93}
94
101[[nodiscard]] constexpr auto log_gamma(float x) -> float {
103}
104
111[[nodiscard]] constexpr auto log_gamma(double x) -> double {
113}
114
115} // namespace num_collect::functions
static constexpr auto gamma(T x) -> T
Calculate a value of gamma function.
static constexpr auto log_gamma(Real x) -> Real
Calculate a natural logarithm of a value of gamma function.
Definition of gamma_lanczos class.
constexpr T pi
Value of pi, .
Definition pi.h:40
Namespace of special functions.
Definition gamma.h:27
constexpr auto log_gamma(float x) -> float
Calculate a natural logarithm of a value of gamma function.
Definition gamma.h:101
constexpr auto gamma(float x) -> float
Calculate a value of gamma function.
Definition gamma.h:35
Definition of pi.