GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/pown.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 20 20 100.0%
Functions: 111 111 100.0%
Branches: 2 2 100.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/rec.hpp>
15
16 namespace plf
17 {
18
19 template<typename Options> struct pown_t : eve::callable<pown_t, Options, raw_option, pedantic_option>
20 {
21 template<concepts::polyfloat_like Z0, concepts::polyfloat_like Z1>
22 13436 POLYFLOAT_ABI constexpr plf::as_polyfloat_like_t<Z0, Z1> operator()(Z0 z, Z1 n) const noexcept
23 requires(!eve::integral_value<Z1>)
24 {
25 13436 return POLYFLOAT_CALL(z, n);
26 }
27
28 template<concepts::polyfloat_like Z, eve::integral_value N>
29 8 POLYFLOAT_ABI constexpr eve::as_wide_as_t<Z, N> operator()(Z z, N n) const noexcept
30 {
31 8 return POLYFLOAT_CALL(z, n);
32 }
33
34 13444 POLYFLOAT_CALLABLE_OBJECT(pown_t, pown_);
35 };
36 //======================================================================================================================
37 //! @addtogroup core
38 //! @{
39 //! @var pown
40 //! @brief return the square value.
41 //!
42 //! @groupheader{Header file}
43 //!
44 //! @code
45 //! #include <polyfloat/core.hpp>
46 //! @endcode
47 //!
48 //! @groupheader{Callable Signatures}
49 //!
50 //! @code
51 //! namespace polyfloat
52 //! {
53 //! template<polyfloat::concepts::polyfloat_like T> constexpr auto pown(T z, auto n) noexcept;
54 //! }
55 //! @endcode
56 //!
57 //! **Parameters**
58 //!
59 //! * `z`: Value to process.
60 //! * `n`: flint exponent (if it is not flint it is truncated before use).
61 //!
62 //! **Return value**
63 //!
64 //! Returns \f$z^\tilda{n}\f$. where \f$\tilda{n}\f$ is the truncature of \f$n\f$n.
65 //!
66 //! @groupheader{Example}
67 //!
68 //! @godbolt{doc/core/pown.cpp}
69 //======================================================================================================================
70
71 inline constexpr auto pown = eve::functor<pown_t>;
72 //======================================================================================================================
73 //! @}
74 //======================================================================================================================
75 }
76
77 namespace plf::_
78 {
79 template<typename Z, eve::integral_value N, eve::callable_options O>
80 8 constexpr auto pown_(POLYFLOAT_DELAY(), O const&, Z const& z, N const& n) noexcept
81 {
82 using r_t = eve::as_wide_as_t<Z, N>;
83 8 return pown(z, plf::convert(n, eve::as(eve::element_type_t<r_t>())));
84 }
85
86 template<typename Z, typename N, eve::callable_options O>
87 13436 constexpr auto pown_(POLYFLOAT_DELAY(), O const&, Z const& z, N nn) noexcept
88 requires(!eve::integral_value<N>)
89 {
90 using r_t = eve::as_wide_as_t<Z, N>;
91 2 if constexpr (dimension_v<Z> == 1 && !eve::integral_value<N>) return eve::pow(z, nn);
92 else
93 {
94 13434 auto isneg = plf::is_ltz(nn);
95 13434 r_t n = plf::abs(r_t(nn));
96 13434 r_t base(z);
97 13434 r_t result(1);
98 13434 r_t h(plf::half(plf::as<r_t>()));
99
2/2
✓ Branch 2 taken 47812 times.
✓ Branch 3 taken 6769 times.
108127 while (eve::any(plf::is_nez(n)))
100 {
101 94693 r_t fac = plf::if_else(is_odd(n), base, one(eve::as(base)));
102 94693 result *= fac;
103 94693 n = plf::floor(n * h);
104 94693 base = plf::sqr(base);
105 }
106 13434 return if_else(isneg, plf::rec(result), result);
107 }
108 }
109 }
110