GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/math/log.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 14 14 100.0%
Functions: 44 44 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 //======================================================================================================================
2 /*
3 POLYFLOAT - Extended precision floating points
4 Copyright : POLYFLOAT Contributors & Maintainers
5 SPDX-License-Identifier: BSL-1.0
6 */
7 //======================================================================================================================
8 #pragma once
9
10 #include <polyfloat/details/callable.hpp>
11 #include <polyfloat/types/concepts.hpp>
12 #include <polyfloat/types/traits.hpp>
13 #include <type_traits>
14 #include <polyfloat/module/core/minus.hpp>
15 #include <polyfloat/module/core/is_negative.hpp>
16 #include <polyfloat/module/math/exp.hpp>
17
18 namespace plf
19 {
20
21 template<typename Options>
22 struct log_t : plf::elementwise_callable<log_t, eve::log_t, Options, raw_option, pedantic_option>
23 {
24 2474 template<concepts::polyfloat_like Z> POLYFLOAT_ABI constexpr Z operator()(Z z) const noexcept
25 {
26 2474 return POLYFLOAT_CALL(z);
27 }
28
29 2464 POLYFLOAT_CALLABLE_OBJECT(log_t, log_);
30 };
31 //======================================================================================================================
32 //! @addtogroup math
33 //! @{
34 //! @var log
35 //! @brief return the natural logarithm value.
36 //!
37 //! @groupheader{Header file}
38 //!
39 //! @code
40 //! #include <polyfloat/core.hpp>
41 //! @endcode
42 //!
43 //! @groupheader{Callable Signatures}
44 //!
45 //! @code
46 //! namespace polyfloat
47 //! {
48 //! template<polyfloat::concepts::polyfloat_like T> constexpr auto log(T z) noexcept;
49 //! }
50 //! @endcode
51 //!
52 //! **Parameters**
53 //!
54 //! * `z`: Value to process.
55 //!
56 //! **Return value**
57 //!
58 //! Returns the expolute,natural logarithm of z.
59 //!
60 //! @groupheader{Example}
61 //!
62 //! @godbolt{doc/math/log.cpp}
63 //======================================================================================================================
64
65 inline constexpr auto log = eve::functor<log_t>;
66 //======================================================================================================================
67 //! @}
68 //======================================================================================================================
69 }
70
71 namespace plf::_
72 {
73
74 2462 template<typename T, eve::callable_options O> constexpr auto log_(POLYFLOAT_DELAY(), O const&, T xx) noexcept
75 {
76 2462 T r(eve::log[eve::pedantic](plf::hi(xx)));
77 2462 auto ex = plf::exp[eve::pedantic](-r);
78 2462 ex = if_else(eve::is_nan(ex), eve::zero, ex);
79 2462 r -= plf::oneminus(xx * ex);
80 if constexpr (dimension_v<T> == 3)
81 {
82 1213 r -= plf::oneminus(xx * plf::exp[pedantic](-r));
83 1213 r -= plf::oneminus(xx * plf::exp[pedantic](-r));
84 }
85 2462 r = if_else(is_ltz(xx) || is_nan(xx), eve::nan, r);
86 2462 r = if_else(is_infinite(xx), plf::inf(as(xx)), r);
87 2462 r = if_else(is_eqz(xx), plf::minf(as(xx)), r);
88 2462 return r;
89 }
90 }
91