tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
exp.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CMATH_EXP_HPP
4#define TETL_CMATH_EXP_HPP
5
6#include <etl/_config/all.hpp>
7
8#include <etl/_3rd_party/gcem/gcem.hpp>
12
13namespace etl {
14
15namespace detail {
16
17inline constexpr struct exp {
18 template <typename Float>
19 [[nodiscard]] constexpr auto operator()(Float arg) const noexcept -> Float
20 {
21 if (not is_constant_evaluated()) {
22#if __has_builtin(__builtin_expf)
23 if constexpr (etl::same_as<Float, float>) {
24 return __builtin_expf(arg);
25 }
26#endif
27#if __has_builtin(__builtin_exp)
28 if constexpr (etl::same_as<Float, double>) {
29 return __builtin_exp(arg);
30 }
31#endif
32 }
33 return etl::detail::gcem::exp(arg);
34 }
35} exp;
36
37} // namespace detail
38
41
44[[nodiscard]] constexpr auto exp(float arg) noexcept -> float { return etl::detail::exp(arg); }
45[[nodiscard]] constexpr auto expf(float arg) noexcept -> float { return etl::detail::exp(arg); }
46[[nodiscard]] constexpr auto exp(double arg) noexcept -> double { return etl::detail::exp(arg); }
47[[nodiscard]] constexpr auto exp(long double arg) noexcept -> long double { return etl::detail::exp(arg); }
48[[nodiscard]] constexpr auto expl(long double arg) noexcept -> long double { return etl::detail::exp(arg); }
49[[nodiscard]] constexpr auto exp(integral auto arg) noexcept -> double { return etl::detail::exp(double(arg)); }
50
52
53} // namespace etl
54
55#endif // TETL_CMATH_EXP_HPP
The concept integral<T> is satisfied if and only if T is an integral type.
Definition integral.hpp:13
constexpr auto expf(float arg) noexcept -> float
Computes e (Euler's number, 2.7182...) raised to the given power arg.
Definition exp.hpp:45
constexpr auto expl(long double arg) noexcept -> long double
Computes e (Euler's number, 2.7182...) raised to the given power arg.
Definition exp.hpp:48
constexpr auto exp(float arg) noexcept -> float
Computes e (Euler's number, 2.7182...) raised to the given power arg.
Definition exp.hpp:44
constexpr auto arg(complex< T > const &z) noexcept -> T
Definition arg.hpp:15
Definition adjacent_find.hpp:8
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:16