GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/mul.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 12 12 100.0%
Functions: 137 137 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/if_else.hpp>
15 #include <polyfloat/module/core/is_not_finite.hpp>
16
17 namespace plf
18 {
19
20 template<typename Options> struct mul_t : eve::strict_tuple_callable<mul_t, Options, raw_option, pedantic_option>
21 {
22 template<concepts::polyfloat_like... Zs>
23 604 POLYFLOAT_ABI constexpr as_polyfloat_like_t<Zs...> operator()(Zs... zs) const noexcept
24 {
25 604 return POLYFLOAT_CALL(zs...);
26 }
27
28 604 POLYFLOAT_CALLABLE_OBJECT(mul_t, mul_);
29 };
30 //======================================================================================================================
31 //! @addtogroup core
32 //! @{
33 //! @var mul
34 //! @brief return the product of the values.
35 //!
36 //! @groupheader{Header file}
37 //!
38 //! @code
39 //! #include <polyfloat/core.hpp>
40 //! @endcode
41 //!
42 //! @groupheader{Callable Signatures}
43 //!
44 //! @code
45 //! namespace polyfloat
46 //! {
47 //! template<polyfloat::concepts::polyfloat_like T1, polyfloat_like Z2> constexpr auto mul(T1 z1, T2 z2) noexcept;
48 //! }
49 //! @endcode
50 //!
51 //! **Parameters**
52 //!
53 //! * `z`: Value to process.
54 //!
55 //! **Return value**
56 //!
57 //! Returns the product of the arguments.
58 //!
59 //! @groupheader{Example}
60 //!
61 //! @godbolt{doc/core/mul.cpp}
62 //======================================================================================================================
63
64 inline constexpr auto mul = eve::functor<mul_t>;
65 //======================================================================================================================
66 //! @}
67 //======================================================================================================================
68
69 49 template<typename Options> constexpr auto neutral(mul_t<Options>) noexcept
70 {
71 49 return plf::one;
72 }
73
74 // Required for optimisation detections
75 using callable_mul_ = eve::tag_t<mul>;
76
77 }
78
79 namespace plf::_
80 {
81 template<typename Z1, typename... Zs, eve::callable_options O>
82 604 constexpr auto mul_(POLYFLOAT_DELAY(), O const& o, Z1 const& z1, Zs const&... zs) noexcept
83 {
84 604 constexpr auto sz = sizeof...(Zs);
85 if constexpr (sz == 0) return z1;
86 544 else if constexpr (sz == 1) return z1 * (zs * ...);
87 else
88 {
89 using r_t = as_polyfloat_like_t<Z1, Zs...>;
90 using e_t = eve::element_type_t<r_t>;
91 96 auto cvt = [](auto a) { return plf::convert(a, as<e_t>()); };
92 60 r_t r0 = cvt(z1);
93 60 ((r0 = mul[o](r0, cvt(zs))), ...);
94 60 return r0;
95 }
96 }
97 }
98