tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
log1p.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_LOG1P_HPP
5#define TETL_CMATH_LOG1P_HPP
6
7#include <etl/_3rd_party/gcem/gcem.hpp>
8#include <etl/_concepts/integral.hpp>
9#include <etl/_type_traits/is_constant_evaluated.hpp>
10
11namespace etl {
12
13namespace detail {
14
15inline constexpr struct log1p {
16 template <typename Float>
17 [[nodiscard]] constexpr auto operator()(Float arg) const noexcept -> Float
18 {
20#if __has_builtin(__builtin_log1pf)
21 if constexpr (etl::same_as<Float, float>) {
22 return __builtin_log1pf(arg);
23 }
24#endif
25#if __has_builtin(__builtin_log1p)
26 if constexpr (etl::same_as<Float, double>) {
27 return __builtin_log1p(arg);
28 }
29#endif
30 }
31 return etl::detail::gcem::log1p(arg);
32 }
33} log1p;
34
35} // namespace detail
36
37/// \ingroup cmath
38/// @{
39
40/// Computes the natural (base e) logarithm of 1+arg. This function is
41/// more precise than the expression etl::log(1+arg) if arg is close to zero.
42/// \details https://en.cppreference.com/w/cpp/numeric/math/log1p
43[[nodiscard]] constexpr auto log1p(float v) noexcept -> float
44{
45 return etl::detail::log1p(v);
46}
47[[nodiscard]] constexpr auto log1pf(float v) noexcept -> float
48{
49 return etl::detail::log1p(v);
50}
51[[nodiscard]] constexpr auto log1p(double v) noexcept -> double
52{
53 return etl::detail::log1p(v);
54}
55[[nodiscard]] constexpr auto log1p(long double v) noexcept -> long double
56{
57 return etl::detail::log1p(v);
58}
59[[nodiscard]] constexpr auto log1pl(long double v) noexcept -> long double
60{
61 return etl::detail::log1p(v);
62}
63[[nodiscard]] constexpr auto log1p(integral auto arg) noexcept -> double
64{
65 return etl::detail::log1p(static_cast<double>(arg));
66}
67
68/// @}
69
70} // namespace etl
71
72#endif // TETL_CMATH_LOG1P_HPP
constexpr auto log1p(long double v) noexcept -> long double
Definition log1p.hpp:55
constexpr auto log1pf(float v) noexcept -> float
Definition log1p.hpp:47
constexpr auto log1pl(long double v) noexcept -> long double
Definition log1p.hpp:59
constexpr auto log1p(double v) noexcept -> double
Definition log1p.hpp:51
constexpr auto log1p(float v) noexcept -> float
Definition log1p.hpp:43
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