GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/sum_of_prod.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 8 8 100.0%
Functions: 15 15 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/abs.hpp>
15
16 namespace plf
17 {
18
19 template<typename Options>
20 struct sum_of_prod_t : eve::strict_tuple_callable<sum_of_prod_t, Options, raw_option, pedantic_option>
21 {
22 template<typename... Ts> struct result : as_polyfloat_like<Ts...>
23 {
24 };
25
26 template<concepts::polyfloat_like T0,
27 concepts::polyfloat_like T1,
28 concepts::polyfloat_like T2,
29 concepts::polyfloat_like T3>
30 requires(eve::same_lanes_or_scalar<T0, T1, T2, T3>)
31 34 POLYFLOAT_ABI typename result<T0, T1, T2, T3>::type constexpr operator()(T0 t0, T1 t1, T2 t2, T3 t3) const noexcept
32 {
33 34 return POLYFLOAT_CALL(t0, t1, t2, t3);
34 }
35
36 34 POLYFLOAT_CALLABLE_OBJECT(sum_of_prod_t, sum_of_prod_);
37 };
38 //======================================================================================================================
39 //! @addtogroup core
40 //! @{
41 //! @var sum_of_prod
42 //! @brief returns `a*b+c*d`.
43 //!
44 //! @groupheader{Header file}
45 //!
46 //! @code
47 //! #include <polyfloat/core.hpp>
48 //! @endcode
49 //!
50 //! @groupheader{Callable Signatures}
51 //!
52 //! @code
53 //! namespace polyfloat
54 //! {
55 //! constexpr auto sum_of_prod(auto a, auto, auto c, auto d) noexcept;
56 //! }
57 //! @endcode
58 //!
59 //! **Parameters**
60 //!
61 //! * `a`, `b`, `c`, `d`: Values to process.
62 //!
63 //! **Return value**
64 //!
65 //! Returns a*b+c*d.
66 //!
67 //! @groupheader{Example}
68 //!
69 //! @godbolt_todo{doc/core/sum_of_prod.cpp}
70 //======================================================================================================================
71
72 inline constexpr auto sum_of_prod = eve::functor<sum_of_prod_t>;
73 //======================================================================================================================
74 //! @}
75 //======================================================================================================================
76
77 using callable_sum_of_prod_ = eve::tag_t<sum_of_prod>;
78
79 }
80
81 namespace plf::_
82 {
83
84 template<typename T1, typename T2, typename T3, typename T4, eve::callable_options O>
85 34 constexpr auto sum_of_prod_(
86 POLYFLOAT_DELAY(), O const& o, T1 const& a, T2 const& b, T3 const& c, T4 const& d) noexcept
87 {
88 if constexpr (O::contains(raw)) return a * b + c * d;
89 else
90 {
91 34 auto cd = mul[o](c, d);
92 34 auto err = fms[o](c, d, cd);
93 34 auto dop = fma[o](a, b, cd);
94 34 return add[o][is_finite(err)](dop, err);
95 }
96 }
97
98 }
99