tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
pow.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_POW_HPP
5#define TETL_CMATH_POW_HPP
6
7#include <etl/_config/all.hpp>
8
9#include <etl/_3rd_party/gcem/gcem.hpp>
10#include <etl/_type_traits/is_constant_evaluated.hpp>
11
12namespace etl {
13
14namespace detail {
15
16inline constexpr struct pow {
17 template <typename Float>
18 [[nodiscard]] constexpr auto operator()(Float base, Float exponent) const noexcept -> Float
19 {
21#if __has_constexpr_builtin(__builtin_powf)
22 if constexpr (etl::same_as<Float, float>) {
23 return __builtin_powf(base, exponent);
24 }
25#endif
26#if __has_constexpr_builtin(__builtin_pow)
27 if constexpr (etl::same_as<Float, double>) {
28 return __builtin_pow(base, exponent);
29 }
30#endif
31 } else {
32#if __has_builtin(__builtin_powf)
33 if constexpr (etl::same_as<Float, float>) {
34 return __builtin_powf(base, exponent);
35 }
36#endif
37#if __has_builtin(__builtin_pow)
38 if constexpr (etl::same_as<Float, double>) {
39 return __builtin_pow(base, exponent);
40 }
41#endif
42 }
43
44 return etl::detail::gcem::pow(base, exponent);
45 }
46} pow;
47
48} // namespace detail
49
50/// \ingroup cmath
51/// @{
52
53/// Computes the value of base raised to the power exp
54/// \details https://en.cppreference.com/w/cpp/numeric/math/pow
55[[nodiscard]] constexpr auto pow(float base, float exp) -> float
56{
57 return etl::detail::pow(base, exp);
58}
59
60/// Computes the value of base raised to the power exp
61/// \details https://en.cppreference.com/w/cpp/numeric/math/pow
62[[nodiscard]] constexpr auto powf(float base, float exp) -> float
63{
64 return etl::detail::pow(base, exp);
65}
66
67/// Computes the value of base raised to the power exp
68/// \details https://en.cppreference.com/w/cpp/numeric/math/pow
69[[nodiscard]] constexpr auto pow(double base, double exp) -> double
70{
71 return etl::detail::pow(base, exp);
72}
73
74/// Computes the value of base raised to the power exp
75/// \details https://en.cppreference.com/w/cpp/numeric/math/pow
76[[nodiscard]] constexpr auto pow(long double base, long double exp) -> long double
77{
78 return etl::detail::pow(base, exp);
79}
80
81/// Computes the value of base raised to the power exp
82/// \details https://en.cppreference.com/w/cpp/numeric/math/pow
83[[nodiscard]] constexpr auto powl(long double base, long double exp) -> long double
84{
85 return etl::detail::pow(base, exp);
86}
87
88/// Computes the value of base raised to the power exp
89/// \details https://en.cppreference.com/w/cpp/numeric/math/pow
90[[nodiscard]] constexpr auto pow(float base, int iexp) -> float
91{
92 return etl::detail::pow(base, static_cast<float>(iexp));
93}
94
95/// Computes the value of base raised to the power exp
96/// \details https://en.cppreference.com/w/cpp/numeric/math/pow
97[[nodiscard]] constexpr auto pow(double base, int iexp) -> double
98{
99 return etl::detail::pow(base, static_cast<double>(iexp));
100}
101
102/// Computes the value of base raised to the power exp
103/// \details https://en.cppreference.com/w/cpp/numeric/math/pow
104[[nodiscard]] constexpr auto pow(long double base, int iexp) -> long double
105{
106 return etl::detail::pow(base, static_cast<long double>(iexp));
107}
108
109/// @}
110
111} // namespace etl
112
113#endif // TETL_CMATH_POW_HPP
constexpr auto pow(long double base, int iexp) -> long double
Computes the value of base raised to the power exp.
Definition pow.hpp:104
constexpr auto powl(long double base, long double exp) -> long double
Computes the value of base raised to the power exp.
Definition pow.hpp:83
constexpr auto pow(float base, int iexp) -> float
Computes the value of base raised to the power exp.
Definition pow.hpp:90
constexpr auto pow(long double base, long double exp) -> long double
Computes the value of base raised to the power exp.
Definition pow.hpp:76
constexpr auto pow(double base, int iexp) -> double
Computes the value of base raised to the power exp.
Definition pow.hpp:97
constexpr auto pow(float base, float exp) -> float
Definition pow.hpp:55
constexpr auto pow(double base, double exp) -> double
Computes the value of base raised to the power exp.
Definition pow.hpp:69
constexpr auto powf(float base, float exp) -> float
Computes the value of base raised to the power exp.
Definition pow.hpp:62
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