GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/math/pow1p.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 9 9 100.0%
Functions: 28 28 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/math/pow_abs.hpp>
15 #include <polyfloat/module/math/log1p.hpp>
16
17 namespace plf
18 {
19
20 template<typename Options>
21 struct pow1p_t : plf::elementwise_callable<pow1p_t, eve::pow1p_t, Options, raw_option, pedantic_option>
22 {
23 template<concepts::polyfloat_like Z1, concepts::polyfloat_like Z2>
24 28 POLYFLOAT_ABI constexpr as_polyfloat_like_t<Z1, Z2> operator()(Z1 z1, Z2 z2) const noexcept
25 {
26 28 return POLYFLOAT_CALL(z1, z2);
27 }
28
29 18 POLYFLOAT_CALLABLE_OBJECT(pow1p_t, pow1p_);
30 };
31 //======================================================================================================================
32 //! @addtogroup math
33 //! @{
34 //! @var pow1p
35 //! @brief return \f$(1+x)^y\f$.
36 //!
37 //! @groupheader{Header file}
38 //!
39 //! @code
40 //! #include <polyfloat/math.hpp>
41 //! @endcode
42 //!
43 //! @groupheader{Callable Signatures}
44 //!
45 //! @code
46 //! namespace polyfloat
47 //! {
48 //! // Regular overload
49 //! constexpr auto pow1p(auto x, auto y) noexcept; // 1
50 //!
51 //! // Lanes masking
52 //! constexpr auto pow1p[conditional_expr c](auto x, auto y) noexcept; // 2
53 //! constexpr auto pow1p[logical_value auto m](auto x, auto y) noexcept; // 2
54 //!
55 //! // Semantic options
56 //! constexpr auto pow1p[raw]( auto x, auto y) noexcept; // 3
57 //! }
58 //! @endcode
59 //!
60 //! **Parameters**
61 //!
62 //! * `z`: Value to process.
63 //!
64 //! **Return value**
65 //!
66 //! 1. Returns the [elementwise](@ref glossary_elementwise) \f$(1+x)^y\f$, with good accuracy,
67 //! even when `x` is small.
68 //! 2. [The operation is performed conditionally](@ref conditional)
69 //! 3. faster but less accurate call.
70 //!
71 //! @groupheader{Example}
72 //!
73 //! @godbolt{doc/math/pow1p.cpp}
74 //======================================================================================================================
75
76 inline constexpr auto pow1p = eve::functor<pow1p_t>;
77 //======================================================================================================================
78 //! @}
79 //======================================================================================================================
80 }
81
82 namespace plf::_
83 {
84
85 template<typename T, typename U, eve::callable_options O>
86 18 constexpr auto pow1p_(POLYFLOAT_DELAY(), O const& o, T a, U b) noexcept
87 {
88 using r_t = as_polyfloat_like_t<T, U>;
89 if constexpr (O::contains(raw))
90 {
91 return plf::dec(plf::pow[o](a, b));
92 }
93 else
94 {
95 using e_t = eve::element_type_t<r_t>;
96 18 auto cvt = [](auto a) { return plf::convert(a, eve::as<e_t>()); };
97 18 auto x = cvt(a);
98 18 auto y = cvt(b);
99 18 auto incx = plf::inc(x);
100 18 return plf::if_else(abs(x) > plf::half(as(x)), plf::pow[o](incx, y), plf::exp[o](y * plf::log1p(x)));
101 }
102 }
103 }
104