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// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_CMATH_LOG_HPP
5#define TETL_CMATH_LOG_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/_type_traits/is_constant_evaluated.hpp>
12
13namespace etl {
14
15namespace detail {
16
17inline constexpr struct log {
18 template <typename Float>
19 [[nodiscard]] constexpr auto operator()(Float v) const noexcept -> Float
20 {
22#if __has_builtin(__builtin_logf)
23 if constexpr (is_same_v<Float, float>) {
24 return __builtin_logf(v);
25 }
26#endif
27#if __has_builtin(__builtin_log)
28 if constexpr (is_same_v<Float, double>) {
29 return __builtin_log(v);
30 }
31#endif
32 }
33
34 return etl::detail::gcem::log(v);
35 }
36} log;
37
38} // namespace detail
39
40/// \ingroup cmath
41/// @{
42
43/// Computes the natural (base e) logarithm of arg.
44/// \details https://en.cppreference.com/w/cpp/numeric/math/log
45[[nodiscard]] constexpr auto log(float v) noexcept -> float
46{
47 return etl::detail::log(v);
48}
49[[nodiscard]] constexpr auto logf(float v) noexcept -> float
50{
51 return etl::detail::log(v);
52}
53[[nodiscard]] constexpr auto log(double v) noexcept -> double
54{
55 return etl::detail::log(v);
56}
57[[nodiscard]] constexpr auto log(long double v) noexcept -> long double
58{
59 return etl::detail::log(v);
60}
61[[nodiscard]] constexpr auto logl(long double v) noexcept -> long double
62{
63 return etl::detail::log(v);
64}
65[[nodiscard]] constexpr auto log(integral auto arg) noexcept -> double
66{
67 return etl::detail::log(double(arg));
68}
69
70/// @}
71
72} // namespace etl
73
74#endif // TETL_CMATH_LOG_HPP
constexpr auto logf(float v) noexcept -> float
Definition log.hpp:49
constexpr auto log(float v) noexcept -> float
Definition log.hpp:45
constexpr auto log(double v) noexcept -> double
Definition log.hpp:53
constexpr auto log(long double v) noexcept -> long double
Definition log.hpp:57
constexpr auto logl(long double v) noexcept -> long double
Definition log.hpp:61
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