GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/cumfun.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 11 11 100.0%
Functions: 242 242 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
15 namespace plf
16 {
17
18 template<typename Options>
19 struct cumfun_t : eve::strict_tuple_callable<cumfun_t, Options, raw_option, pedantic_option>
20 {
21 template<typename T> using return_type = T;
22
23 template<typename... Ts>
24 using result = kumi::result::fill_t<sizeof...(Ts), return_type<plf::as_polyfloat_like_t<Ts...>>>;
25
26 template<eve::product_type Tup>
27 using tuple_result = kumi::result::fill_t<Tup::size(), return_type<kumi::apply_traits_t<as_polyfloat_like, Tup>>>;
28
29 template<typename F, concepts::polyfloat_like... Zs>
30 80 POLYFLOAT_ABI result<Zs...> constexpr operator()(F f, Zs const&... zs) const noexcept
31 {
32 80 return POLYFLOAT_CALL(f, zs...);
33 }
34
35 template<typename F, eve::non_empty_product_type PT>
36 282 POLYFLOAT_ABI constexpr tuple_result<PT> operator()(F f, PT t) const noexcept
37 {
38 282 return POLYFLOAT_CALL(f, t);
39 }
40
41 362 POLYFLOAT_CALLABLE_OBJECT(cumfun_t, cumfun_);
42 };
43 //======================================================================================================================
44 //! @addtogroup core
45 //! @{
46 //! @var cumfun
47 //! @brief convert a pack of values into
48 //! a tuple of the cumulative application of a two parameter eve fonction defining
49 //! an abelian monoid.
50 //!
51 //! @groupheader{Header file}
52 //!
53 //! @code
54 //! #include <polyfloat/module/core.hpp>
55 //! @endcode
56 //!
57 //! @groupheader{Callable Signatures}
58 //!
59 //! @code
60 //! namespace plf
61 //! {
62 //! // Regular overloads
63 //! constexpr auto cumfun(auto f, eve::value auto ... xs) noexcept; // 1
64 //! constexpr auto cumfun(auto f, non_empty_product_type tup) noexcept; // 2
65 //!
66 //! }
67 //! @endcode
68 //!
69 //! **Parameters**
70 //!
71 //! * `f`: invocable of two arguments.
72 //! * `xs...`: [values](@ref eve::value) arguments.
73 //! * `tup`: kumi tuple of values.
74 //!
75 //! **Return value**
76 //!
77 //! 1. return a kumi tuple of the values of the cumulated values of all `xs` converted to
78 //! the element type of the common value of the `xs` using f.
79 //! 2. same as 1., using the tuple elements.
80 //!
81 //! @note currently cumfun can only be applied with `f` being one of these POLYFLOAT functors :
82 //! `add`, `mul`, `min`, `max` that define abelian monoids and each possess
83 //! a well defined neutral element.
84 //!
85 //! @groupheader{Example}
86 //! @godbolt{doc/core/cumfun.cpp}
87 //================================================================================================
88 inline constexpr auto cumfun = eve::functor<cumfun_t>;
89 //================================================================================================
90 //! @}
91 //================================================================================================
92 }
93
94 namespace plf::_
95 {
96 template<typename F, eve::product_type PT, eve::callable_options O>
97 282 constexpr auto cumfun_(POLYFLOAT_DELAY(), O const& o, F f, PT tup) noexcept
98 {
99 if constexpr (PT::size() == 0) return kumi::make_tuple();
100 else
101 {
102 using e_t = kumi::apply_traits_t<plf::as_polyfloat_like, PT>;
103 282 auto n = neutral(f)(eve::as<e_t>());
104 362 auto cvt = [](auto a) { return plf::convert(a, eve::as_element<e_t>{}); };
105 564 return kumi::inclusive_scan_left(f[o], kumi::map(cvt, tup), n);
106 }
107 }
108
109 template<typename F, typename... Ts, eve::callable_options O>
110 80 constexpr auto cumfun_(POLYFLOAT_DELAY(), O const& o, F f, Ts... ts) noexcept
111 {
112 160 return plf::cumfun[o](f, kumi::make_tuple(ts...));
113 }
114 }
115