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// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_CMATH_EXP_HPP
5#define TETL_CMATH_EXP_HPP
6
7#include <etl/_config/all.hpp>
8
9#include <etl/_3rd_party/gcem/gcem.hpp>
10#include <etl/_concepts/integral.hpp>
11#include <etl/_concepts/same_as.hpp>
12#include <etl/_type_traits/is_constant_evaluated.hpp>
13
14namespace etl {
15
16namespace detail {
17
18inline constexpr struct exp {
19 template <typename Float>
20 [[nodiscard]] constexpr auto operator()(Float arg) const noexcept -> Float
21 {
23#if __has_builtin(__builtin_expf)
24 if constexpr (etl::same_as<Float, float>) {
25 return __builtin_expf(arg);
26 }
27#endif
28#if __has_builtin(__builtin_exp)
29 if constexpr (etl::same_as<Float, double>) {
30 return __builtin_exp(arg);
31 }
32#endif
33 }
34 return etl::detail::gcem::exp(arg);
35 }
36} exp;
37
38} // namespace detail
39
40/// \ingroup cmath
41/// @{
42
43/// Computes e (Euler's number, 2.7182...) raised to the given power arg
44/// \details https://en.cppreference.com/w/cpp/numeric/math/exp
45[[nodiscard]] constexpr auto exp(float arg) noexcept -> float
46{
47 return etl::detail::exp(arg);
48}
49[[nodiscard]] constexpr auto expf(float arg) noexcept -> float
50{
51 return etl::detail::exp(arg);
52}
53[[nodiscard]] constexpr auto exp(double arg) noexcept -> double
54{
55 return etl::detail::exp(arg);
56}
57[[nodiscard]] constexpr auto exp(long double arg) noexcept -> long double
58{
59 return etl::detail::exp(arg);
60}
61[[nodiscard]] constexpr auto expl(long double arg) noexcept -> long double
62{
63 return etl::detail::exp(arg);
64}
65[[nodiscard]] constexpr auto exp(integral auto arg) noexcept -> double
66{
67 return etl::detail::exp(double(arg));
68}
69
70/// @}
71
72} // namespace etl
73
74#endif // TETL_CMATH_EXP_HPP
constexpr auto expf(float arg) noexcept -> float
Definition exp.hpp:49
constexpr auto exp(double arg) noexcept -> double
Definition exp.hpp:53
constexpr auto exp(long double arg) noexcept -> long double
Definition exp.hpp:57
constexpr auto expl(long double arg) noexcept -> long double
Definition exp.hpp:61
constexpr auto exp(float arg) noexcept -> float
Definition exp.hpp:45
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