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