tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
tgamma.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_CMATH_TGAMMA_HPP
5#define TETL_CMATH_TGAMMA_HPP
6
7#include <etl/_3rd_party/gcem/gcem.hpp>
8#include <etl/_concepts/integral.hpp>
9#include <etl/_type_traits/is_constant_evaluated.hpp>
10
11namespace etl {
12
13namespace detail {
14
15inline constexpr struct tgamma {
16 template <typename Float>
17 [[nodiscard]] constexpr auto operator()(Float arg) const noexcept -> Float
18 {
20#if __has_builtin(__builtin_tgammaf)
21 if constexpr (etl::same_as<Float, float>) {
22 return __builtin_tgammaf(arg);
23 }
24#endif
25#if __has_builtin(__builtin_tgamma)
26 if constexpr (etl::same_as<Float, double>) {
27 return __builtin_tgamma(arg);
28 }
29#endif
30 }
31 return etl::detail::gcem::tgamma(arg);
32 }
33} tgamma;
34
35} // namespace detail
36
37/// \ingroup cmath
38/// @{
39
40/// Computes the gamma function of arg.
41/// \details https://en.cppreference.com/w/cpp/numeric/math/tgamma
42[[nodiscard]] constexpr auto tgamma(float arg) noexcept -> float
43{
44 return etl::detail::tgamma(arg);
45}
46[[nodiscard]] constexpr auto tgammaf(float arg) noexcept -> float
47{
48 return etl::detail::tgamma(arg);
49}
50[[nodiscard]] constexpr auto tgamma(double arg) noexcept -> double
51{
52 return etl::detail::tgamma(arg);
53}
54[[nodiscard]] constexpr auto tgamma(long double arg) noexcept -> long double
55{
56 return etl::detail::tgamma(arg);
57}
58[[nodiscard]] constexpr auto tgammal(long double arg) noexcept -> long double
59{
60 return etl::detail::tgamma(arg);
61}
62[[nodiscard]] constexpr auto tgamma(integral auto arg) noexcept -> double
63{
64 return etl::detail::tgamma(static_cast<double>(arg));
65}
66
67/// @}
68
69} // namespace etl
70
71#endif // TETL_CMATH_TGAMMA_HPP
constexpr auto tgamma(float arg) noexcept -> float
Definition tgamma.hpp:42
constexpr auto tgamma(long double arg) noexcept -> long double
Definition tgamma.hpp:54
constexpr auto tgammaf(float arg) noexcept -> float
Definition tgamma.hpp:46
constexpr auto tgamma(double arg) noexcept -> double
Definition tgamma.hpp:50
constexpr auto tgammal(long double arg) noexcept -> long double
Definition tgamma.hpp:58
Definition adjacent_find.hpp:9
constexpr auto is_constant_evaluated() noexcept -> bool
Detects whether the function call occurs within a constant-evaluated context. Returns true if the eva...
Definition is_constant_evaluated.hpp:17