GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/cumprod.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 7 7 100.0%
Functions: 64 64 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/cumfun.hpp>
15
16 namespace plf
17 {
18
19 template<typename Options>
20 struct cumprod_t : eve::strict_tuple_callable<cumprod_t, Options, raw_option, pedantic_option>
21 {
22 template<typename T> using return_type = T;
23
24 template<typename... Ts>
25 using result = kumi::result::fill_t<sizeof...(Ts), return_type<plf::as_polyfloat_like_t<Ts...>>>;
26
27 template<eve::product_type Tup>
28 using tuple_result = kumi::result::fill_t<Tup::size(), return_type<kumi::apply_traits_t<as_polyfloat_like, Tup>>>;
29
30 template<concepts::polyfloat_like... Zs>
31 96 POLYFLOAT_ABI result<Zs...> constexpr operator()(Zs const&... zs) const noexcept
32 {
33 96 return POLYFLOAT_CALL(zs...);
34 }
35
36 1 template<eve::non_empty_product_type PT> POLYFLOAT_ABI constexpr tuple_result<PT> operator()(PT t) const noexcept
37 {
38 1 return POLYFLOAT_CALL(t);
39 }
40
41 98 POLYFLOAT_CALLABLE_OBJECT(cumprod_t, cumprod_);
42 };
43 //======================================================================================================================
44 //! @addtogroup core
45 //! @{
46 //! @var cumprod
47 //! @brief convert a pack of values into
48 //! a tuple of the cumulative product of its values
49 //!
50 //! @groupheader{Header file}
51 //!
52 //! @code
53 //! #include <polyfloat/module/core.hpp>
54 //! @endcode
55 //!
56 //! @groupheader{Callable Signatures}
57 //!
58 //! @code
59 //! namespace plf
60 //! {
61 //! // Regular overloads
62 //! constexpr auto cumprod(auto ... xs) noexcept; // 1
63 //! constexpr auto cumprod(non_empty_product_type tup) noexcept; // 2
64 //!
65 //! }
66 //! @endcode
67 //!
68 //! **Parameters**
69 //!
70 //! * `xs...`: [polyfloat like](@ref plf::concepts::polyfloat_like) arguments.
71 //! * `tup`: kumi tuple of values.
72 //!
73 //! **Return value**
74 //!
75 //! 1. return a kumi tuple of the values of the cumulated products of all `xs` converted to
76 //! the element type of the common polyfloat like value of the `xs`.
77 //! 2. same as 1., using the tuple elements.
78 //!
79 //!
80 //! @groupheader{Example}
81 //! @godbolt{doc/core/cumprod.cpp}
82 //================================================================================================
83 inline constexpr auto cumprod = eve::functor<cumprod_t>;
84 //================================================================================================
85 //! @}
86 //================================================================================================
87 }
88
89 namespace plf::_
90 {
91 template<eve::product_type PT, eve::callable_options O>
92 constexpr auto cumprod_(POLYFLOAT_DELAY(), O const& o, PT tup) noexcept
93 {
94 return plf::cumfun[o](plf::mul, tup);
95 }
96
97 template<typename... Ts, eve::callable_options O>
98 98 constexpr auto cumprod_(POLYFLOAT_DELAY(), O const& o, Ts... ts) noexcept
99 {
100 196 return plf::cumfun[o](plf::mul, kumi::make_tuple(ts...));
101 }
102 }
103